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

前端 未结 6 990
粉色の甜心
粉色の甜心 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:19

    As mentionned in the accepted answer, ViewData.TemplateInfo.HtmlFieldPrefix gives you the property name inside an EditorTemplate.

    I think it is worth saying that you can use an empty string inside the HtmlHelper functions if your goal is to generate an input/select. It will use the model's property name.

    @Html.TextBox("", theValue, new { @class = "form-control" })
    

    or

    @Html.DropDownList("", new List(), theValue, new { @class = "form-control" })
    

提交回复
热议问题