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

前端 未结 6 991
粉色の甜心
粉色の甜心 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 02:54

    For future reference (old question), I found this: System.Web.Mvc.Html.NameExtensions.

    Using those, you can do something like

    
    

    And you'll get

    
    

    There are several other related helpers in this extension class. This method does more than just get the property name, though. For example, you could use m.MyProperty.MySubProperty and you'd get a valid HTML name for posting.

提交回复
热议问题