4

I just had some great advice on how to set the width of an input field in MVC:

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

Now I hav tried it for another type of field but it doesn't work:

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

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

Bev

JudyJ
  • 597
  • 5
  • 7
  • 14
  • possible duplicate of [EditorFor() and html properties](http://stackoverflow.com/questions/1625327/editorfor-and-html-properties) – amit_g May 06 '11 at 16:09
  • Look [another one](http://stackoverflow.com/questions/3735400/html-attributes-for-editorfor-in-asp-net-mvc) – amit_g May 06 '11 at 16:10

4 Answers4

6

If you need to use EditorFor and not TextBoxFor and have multiple editors on the page, but only need to change the width of specific ones... The easiest what is to add a css style to the class ID as such:

<style type="text/css">
    input#Status.BrowserTitle { width: 80px; }
</style>
Mike B
  • 61
  • 1
  • 3
3

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

A far better approach would be to use a CSS

input { width: 80em; }
David Glenn
  • 24,412
  • 19
  • 74
  • 94
0

I have answered this here:

https://stackoverflow.com/a/10200839/1280068

for MVC3 use

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

@BrowserTitle
Community
  • 1
  • 1
Stuart Dobson
  • 3,001
  • 4
  • 35
  • 37
0

Overwriting the css worked for me:

.text-box
{
    width: 625px;
}

.multi-line.text-box
{
    height: 25px;
}

textarea
{
    min-height: 25px;
}
FROgistics
  • 95
  • 1
  • 1