好的我正在使用MVC 4與Bootstrap並運行TextAreaFor和列的問題。默認情況下,如果您未設置列/行,則系統將默認爲2/10。很明顯,如果你輸入行/列將會使用它。問題出在使用Bootstraper的表單上,如果你只留下空白就更好。任何人都想出了禁用TextAreaFor的col的好方法。用TextAreaFor禁用cols
@Html.TextAreaFor(m=> m.Comments, new { htmlAttributes = new { @class = "form-control" } })
輸出:
<textarea cols="20" htmlAttributes="{ class = form-control }" id="Comments" name="Comments" rows="2"></textarea>
,但我想這一點:
當然<textarea htmlAttributes="{ class = form-control }" id="Comments" name="Comments" rows="2"></textarea>
這工作,但並不友好:
<textarea id="Comments" name="Comments" rows="10" class="form-control">@Model.Comments</textarea>
編輯 - 哦我創建了一個自定義編輯器模板,例如:
@{
string id = ViewData.ModelMetadata.PropertyName;
string rows = string.Empty;
if (ViewData["rows"] != null)
{
rows = string.Format("rows={0}", ViewData["rows"]);
}
}
<textarea id="@id" name="@id" @rows class="form-control">@Model</textarea>
用法:
@Html.EditorFor(model => model.Comments, "TextAreaCustom", new { @rows = 10 })
當山坳屬性不存在自舉將文本區域設置爲它所在div的100%。顯然,當col被設置時,它就是這個寬度,所以如果他改變大小,或者該框看起來太小或比屏幕大。我試圖將所有表單設置爲基於瀏覽器大小使用xs/sm/md大小。 – 2014-09-22 20:10:10
這是我的觀點:Bootstrap樣式覆蓋了屬性,因爲它們爲textarea設置了明確的寬度。如果這沒有發生,那麼Bootstrap樣式就會以某種方式頂起來。假設textarea具有必要的「表格控制」類,無論「cols」設置爲什麼或者甚至設置了什麼,寬度都應該是容器的100%。 – 2014-09-22 21:41:26