I just needed to set the size of one textbox on one page. Coding attributes on the model and creating custom editor templates were overkill, so I just wrapped the @Html.EditorFor call with a span tag that called a class which specifies the size of the textbox.
No need to create custom template for MVC 4. Use TextBox instead of EditFor here special html attributes are not supported, it is only supported from MVC 5. TextBox is should support for MVC 4, I don't know about other version.
Adding a class to Html.EditorFor doesn't make sense as inside its template you could have many different tags. So you need to assign the class inside the editor template:
I just needed to set the size of one textbox on one page. Coding attributes on the model and creating custom editor templates were overkill, so I just wrapped the @Html.EditorFor call with a span tag that called a class which specifies the size of the textbox.
CSS class declaration:
View code:
does not allow any arguments to be passed in for the Text box
This is how you can apply attributes.
I used another solution using CSS attribute selectors to get what you need.
Indicate the HTML attribute you know and put in the relative style you want.
Like below:
No need to create custom template for MVC 4. Use TextBox instead of EditFor here special html attributes are not supported, it is only supported from MVC 5. TextBox is should support for MVC 4, I don't know about other version.
You can use:
(At least with ASP.NET MVC 5, but I do not know how that was with ASP.NET MVC 3.)
Adding a class to
Html.EditorFor
doesn't make sense as inside its template you could have many different tags. So you need to assign the class inside the editor template:and in the custom template: