I have the following line in my view:
<div class="editor-field"> <%= Html.TextBoxFor(m => m.Description)%> </div>
How do I define the width of the text box?
Both of them provide the same HTML output, “HTML. TextBoxFor” is strongly typed while “HTML. TextBox” isn't. Below is a simple HTML code which just creates a simple textbox with “CustomerCode” as name.
The HtmlHelper class includes two extension methods TextBox() and TextBoxFor<TModel, TProperty>() that renders the HTML textbox control <input type="text"> in the razor view. It is recommended to use the generic TextBoxFor<TModel, TProperty>() method, which is less error prons and performs fast.
This worked for me for the one-offs, pretty verbose though:
<%: Html.TextBoxFor(m => m.Description, new { style="width:50px;" })%>
A reusable solution is to set the width in your css file
.wide { width: 300px; }
then set it using the markup above
<%= Html.TextBoxFor(m => m.Description, new { @class= "wide" })%>
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