Width of input fields using editor in MVC3

I have only a few tips on how to set input box width in MVC:

@Html.TextBoxFor(model => model.Status.RowKey, new { size = 200, disabled = "disabled", @readonly = "readonly" }) 

Now I tried it for a different type of field, but it does not work:

 @Html.EditorFor(model => model.Status.BrowserTitle, new { size = 80 }) 

I would also like to set this to 80 characters, but when I do this, the source does not change and does not show 80.

Bev

+4
source share
4 answers

If you need to use EditorFor, not TextBoxFor, and you have several editors on the page, but you just need to change the width of the specific ... The simplest thing is to add a CSS style to the class identifier:

 <style type="text/css"> input#Status.BrowserTitle { width: 80px; } </style> 
+6
source

Because you are using Html.EditorFor , not Html.TextBoxFor .

It’s much better to use CSS.

 input { width: 80em; } 
+3
source

I answered this here:

fooobar.com/questions/52668 / ...

for using MVC3

 @{ HtmlString BrowserTitle= new HtmlString(Html.EditorFor(model => model.Status.BrowserTitle).ToString().Replace("class=\"text-box single-line\"", "class=\"text-box single-line my80wideClass\"")); } @BrowserTitle 
0
source

Overwriting css worked for me:

 .text-box { width: 625px; } .multi-line.text-box { height: 25px; } textarea { min-height: 25px; } 
0
source

All Articles