HtmlHelper NameFor method

匆匆过客 提交于 2019-12-10 12:36:28

问题


Is there an Html.NameFor feature, that gets the name html attribute for a model item?

I'd like to use the following code in my Razor view:

<input type="text" value="@Model.User.Email" name="@Html.NameFor(x => x.User.Email)">

回答1:


Html.NameFor is now included in MVC 4.




回答2:


Yes, there is Html.NameFor method in the ASP.NET MVC Futures assembly.




回答3:


If you just want to get the value for a name attribute that will work when binding the input back to your model you could use the ExpressionHelper.GetExpressionText method. However invoking it would involve some code gymnastics.

How about just using the TextBoxFor helper?

@Html.TextBoxFor(Model => Model.User.Email)


来源:https://stackoverflow.com/questions/3444021/htmlhelper-namefor-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!