How can I get the property name in my MVC3 custom Editor Template

前端 未结 6 993
粉色の甜心
粉色の甜心 2021-02-01 02:41

I have an enumeration in my project and I\'ve created a custom editor template for this enumeration. So, now any model I have with a property with a type of this enumeration, wi

6条回答
  •  逝去的感伤
    2021-02-01 03:11

    How about the following template:

    @model ItemEnumerations.ItemType
    @{
        var values = 
            from value in Enum.GetValues(typeof(ItemType)).Cast()
            select new { ID = (int)value, Name = value.ToString() };
        var list = new SelectList(values , "ID", "Name", (int)Model);
    }
    @Html.DropDownList("", list)
    

    This way you don't need to manually render

    提交评论

提交回复
热议问题