How to read name of html helper element

做~自己de王妃 提交于 2019-12-05 07:09:38
archil

@Html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName("Name") Or you can use extension method for generic HtmlHelper to use this with Lambda Expressions

public static string GetFullHtmlFieldName<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
{
    return htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(ExpressionHelper.GetExpressionText(expression));
}

The use would be (Html.GetFullHtmlFieldName(x => x.Name)

I'm guessing this is only in newer versions of MVC, but you could probably just use:

@Html.NameFor(x => x.Name)

Documentation: http://msdn.microsoft.com/en-us/library/hh833703(v=vs.108).aspx

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