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

2

4 Answers 4

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> 
    3

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

    A far better approach would be to use a CSS

    input { width: 80em; } 
      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 
        0

        Overwriting the css worked for me:

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

          Start asking to get answers

          Find the answer to your question by asking.

          Ask question

          Explore related questions

          See similar questions with these tags.