views:

798

answers:

3

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?

+1  A: 

You can attach it as an attribute. Try this:

<div class="editor-field">
     <%= Html.TextBoxFor(m => m.Description, new { style = "20em;" })%>                     
</div>
Chris Pebble
+6  A: 

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" })%> 
Cheddar
+4  A: 

This worked for me for the one-offs, pretty verbose though:

<%: Html.TextBoxFor(m => m.Description, new { style="width:50px;" })%>
Josh