2011-05-06 35 views
4

使用EditorFor輸入欄的寬度我只是對如何設置輸入字段的MVC中的寬一些很好的建議:在MVC3

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

現在,我甲肝嘗試了另一種類型的字段,但它不「T工作:

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

我還要設置這個爲80個字符,但是當我這樣做的源不會改變,不顯示80

BEV

+0

可能重複http://stackoverflow.com/questions/1625327/ editorfor-and-html-properties) – 2011-05-06 16:09:25

+0

Look [another one](http://stackoverflow.com/questions/3735400/html-attributes-for-editorfor-in-asp-net-mvc) – 2011-05-06 16:10:36

回答

3

因爲您正在使用Html.EditorFor而不是Html.TextBoxFor

一個更好的辦法是使用CSS

input { width: 80em; } 
6

如果您需要使用EditorFor而不是TextBoxFor並在頁面上多個編輯器,而只需要更改特定的人的寬度.. 。最簡單的是一個css樣式添加到類ID爲這樣:

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

我已經回答了這個位置:

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

爲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

重寫的CSS工作對我來說:

.text-box 
{ 
    width: 625px; 
} 

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

textarea 
{ 
    min-height: 25px; 
} 
的[EditorFor()和HTML屬性(