MVC2 EditorTemplate for DropDownList

后端 未结 3 352
天涯浪人
天涯浪人 2021-01-30 07:25

I\'ve spent the majority of the past week knee deep in the new templating functionality baked into MVC2. I had a hard time trying to get a DropDownList template working. The b

3条回答
  •  情歌与酒
    2021-01-30 08:02

    Perfect. This is what I'm looking for. Thanks!

    But your example model is simple model. How about a complex viewmodel like

    public class MaintainServicePackageViewModel
    {
        public IEnumerable ServicePackageWithOwnerName { get; set; }
        public ServicePackageWithOwnerName CurrentServicePackage { get; set; }
        public IEnumerable ServiceInPackage { get; set; }
    }
    
    public class ServicePackageWithOwnerName : ServicePackage
    {
        [UIHint("DropDownList")]
        [DropDownList(DropDownListTargetProperty = "Owner")]
        [DisplayNameLocalized(typeof(Resources.Globalization), "OwnerName")]
        public IEnumerable OwnerName { get; set; }
    }
    

    The OwnerName is set to a dropdownlist, but it is not a direct element of the viewmodel instead it's a child element of ServicePackageWithOwnerName which is the element of the viewmodel. In such condition, there's no way to set the OwnerName value in the controller, how to fix this? Appreciate!

    Regards

    Jack

提交回复
热议问题