Asp.net-Mvc

如何在 ASP.MVC 中指定多行編輯器的列和行?

  • June 2, 2011

在 ASP.MVC 3 中,如何為多行EditorFor(文本區域)指定列和行?我正在使用[UIHint("MultilineText")],但找不到任何有關如何為文本區域添加屬性的文件。

所需的 HTML:

<textarea cols="40" rows="10"></textarea>

我的 MVC 3 模型的相關部分:

[UIHint("MultilineText")]
public string Description { get; set; }

我的 Razor cshtml 的相關部分:

<div class="editor-field">
   @Html.EditorFor(model => model.Description)
</div>

我在查看原始碼中得到了什麼:

<div class="editor-field">
    <textarea class="text-box multi-line" id="Description" name="Description"></textarea>
</div>

如何設置行和列?

使用 TextAreaFor

@Html.TextAreaFor(model => model.Description, new { @class = "whatever-class", @cols = 80, @rows = 10 })

或使用樣式來multi-line上課。

您也可以為此編寫EditorTemplate 。

引用自:https://stackoverflow.com/questions/6217908