I want to manually define id and name for textbox like that:
<%: Html.TextBoxFor(model => model.Name, new { @id = "txt1", @name = "txt1" })%>
But only the id is changed, not the name attribute, why?
<input id="txt1" name="Name" type="text" value="">
Thank you!
Ultimately they both produce the same HTML but Html. TextBoxFor() is strongly typed where as Html. TextBox isn't.
TextBoxFor represents a single-line input control that allows end-users to enter text.
The TextBoxes can be made ReadOnly by setting the HTML ReadOnly attribute using the HtmlAttributes parameter in Html. TextBox and Html. TextBoxFor helper functions. Note: For beginners in ASP.Net MVC, please refer my article ASP.Net MVC Hello World Tutorial with Sample Program example.
The MaxLength for TextBoxes is set using the HTML MaxLength attribute using the HtmlAttributes parameter in Html. TextBox and Html. TextBoxFor helper functions.
This is ok:
<%: Html.TextBoxFor(model => model.Name, new { Name = "txt1" })%>
Do you write "Name" instead of "name"?
Output:
<input name="txt1" type="text" value="">
Actually you can... just use Name
with first letter capitalized instead of name
:
@Html.TextBoxFor(model => model.Property, new { Name = "myName" })
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