开发者

Width of input fields using EditorFor in MVC3

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


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>


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

A far better approach would be to use a CSS

input { width: 80em; }


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


Overwriting the css worked for me:

.text-box
{
    width: 625px;
}

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

textarea
{
    min-height: 25px;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜