Existe-t-il dans mvc une possibilité de lire un nom qui sera atsortingbué au contrôle HTML?
Par exemple j’utilise ce code:
@Html.LabelFor(x => x.Name) @Html.TextBoxFor(x => x.Name) @Html.ValidationMessageFor(x => x.Name) @Html.HiddenFor(x => x.Id) I want to display here a TextBox name
Et je veux obtenir un nom de nom d’entrée. Ce code est un fragment de vue partielle. Le nom de l’élément ressemble à l’ enfant [1] .Name
@ Html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName (“Nom”) Ou vous pouvez utiliser la méthode d’extension pour HtmlHelper générique pour l’utiliser avec les expressions lambda
public static ssortingng GetFullHtmlFieldName(this HtmlHelper htmlHelper, Expression> expression) { return htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(ExpressionHelper.GetExpressionText(expression)); }
L’utilisation serait (Html.GetFullHtmlFieldName(x => x.Name)
Je suppose que cela ne concerne que les versions les plus récentes de MVC, mais vous pourriez probablement simplement utiliser:
@Html.NameFor(x => x.Name)
Documentation: http://msdn.microsoft.com/en-us/library/hh833703(v=vs.108).aspx