如何阅读HTML辅助元素的名称 [英] How to read name of html helper element
本文介绍了如何阅读HTML辅助元素的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何MVC机会阅读将被分配到HTML控件的名称?
Is there in mvc any opportunity to read a name which will be assigned to html control?
例如我用这个code:
For example I use this code:
<div>
@Html.LabelFor(x => x.Name)
@Html.TextBoxFor(x => x.Name)
@Html.ValidationMessageFor(x => x.Name)
@Html.HiddenFor(x => x.Id)
<div>
I want to display here a TextBox name
</div>
</div>
和我想要得到的输入名称的名称。这code是局部视图的片段。
元素的名称看起来像的儿童[1] .Name点的
And I want to get a name of input name. This code is fragment of partial view. Name of element looks like children[1].Name
推荐答案
@ Html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(姓名)
或者你可以使用扩展方法用于一般的HtmlHelper与LAMBDA防爆pressions使用
@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));
}
使用将(Html.GetFullHtmlFieldName(X =&GT; x.Name)
这篇关于如何阅读HTML辅助元素的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文