試圖自舉類添加到由EditorFor生成的輸入,但沒有工作...如何添加html類到asp.net mvc 4 html helpers?
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
不使用輔助工作的罰款:
<input class ="form-control" name="Name" type="Text" value="@Model.Nome" />
你的方式是正確的@Rieth。它應該工作。在瀏覽器中使用F12即開發人員工具,並檢查爲元素生成的html以及應用於元素的樣式/類是什麼。你可以從那裏得到線索。 –
您無法將屬性添加到MVC-4中的EditorFor()。該功能直到MVC-5.1才被添加。你需要使用'@ Html.EditorFor(m => m.Name,new {@class =「form-control」})' –