MVC : How to add attribute, class, readonly, custom attribute to @Html helper classes in MVC like @Html.TextBoxFor
Here I am using the examples for @Html.TextBoxFor class.
1) Adding attributes
@Html.TextBoxFor(model=>model.FirstName,new{ Width="200px" })
2) Adding Custom attribute
@Html.TextBoxFor(model=>model.FirstName,new{ @data_type="number" })
Note : data_type will be converted to data-type by Razor engine.
3) Readonly & Class
@Html.TextBoxFor(model=>model.FirstName,new{ @readonly="readonly", @class="firstname" })
1) Adding attributes
@Html.TextBoxFor(model=>model.FirstName,new{ Width="200px" })
2) Adding Custom attribute
@Html.TextBoxFor(model=>model.FirstName,new{ @data_type="number" })
Note : data_type will be converted to data-type by Razor engine.
3) Readonly & Class
@Html.TextBoxFor(model=>model.FirstName,new{ @readonly="readonly", @class="firstname" })
Comments
Post a Comment