Is there in mvc any opportunity to read a name which will be assigned to html control?
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>
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
Tag helper is a new feature in ASP.net MVC. It enables server-side code to create and render HTML elements in Razor View. It is feature of Razor View engine. They are the C# classes which participate in view generation by creating the HTML elements.
The HtmlHelper class renders HTML controls in the razor view. It binds the model object to HTML controls to display the value of model properties into those controls and also assigns the value of the controls to the model properties while submitting a web form.
These helpers are used to render the most common types of HTML elements such as HTML text boxes, checkboxes and so on. To create a HTML form, we can use the BeginForm() and EndForm() extension methods of the HTML helper class.
What is HTML Helper in ASP.NET MVC 5? HTML Helpers are methods that return a string. Helper class can create HTML controls programmatically. HTML Helpers are used in View to render HTML content.
@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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With