How can translate that line using TextBoxFor (MVC):
<input id="Name" name="Name" type="text" data-bind="value: Name" class="title width-7" />
Thanks
The TextBox for the Name value is created using Html. TextBoxFor function while the TextBox for the Mobile Number value is created using Html. TextBox helper function. The MaxLength of both the TextBoxes is set using the HTML MaxLength attribute using the HtmlAttributes parameter in Html.
IMO the main difference is that Textbox is not strongly typed. TextboxFor take a lambda as a parameter that tell the helper the with element of the model to use in a typed view. You can do the same things with both, but you should use typed views and TextboxFor when possible.
TextBoxFor<TModel,TProperty>(HtmlHelper<TModel>, Expression<Func<TModel,TProperty>>, Object) Returns a text input element for each property in the object that is represented by the specified expression, using the specified HTML attributes.
MVC 3 will translate underscores in html attribute names into hyphens, so something like this should do the trick
@Html.TextBoxFor(m => m.Name, new { data_bind="value: Name", @class = "title width-7" })
For example,
if you want to add data-mask
@Html.TextBoxFor(m => m.BirthDate, new { @class = "form-control", data_mask = "date" })
it will generate in html
data-mask="date"
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