如何在 ASP.MVC 中指定多行 Editor-For 的列和行? [英] How do I specify the columns and rows of a multiline Editor-For in ASP.MVC?
本文介绍了如何在 ASP.MVC 中指定多行 Editor-For 的列和行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 ASP.MVC 3 中,如何为多行 EditorFor
(textarea) 指定列和行?我正在使用 [UIHint("MultilineText")]
,但找不到有关如何为文本区域添加属性的任何文档.
所需的 HTML:
<textarea cols="40" rows="10"></textarea>
我的 MVC 3 模型的相关部分:
[UIHint("MultilineText")]公共字符串 描述 { 获取;放;}
我的 Razor cshtml 的相关部分:
@Html.EditorFor(model => model.Description)
我在查看源代码中得到了什么:
<textarea class="text-box multi-line" id="Description" name="Description"></textarea>
如何设置行和列?
解决方案
Use TextAreaFor
@Html.TextAreaFor(model => model.Description, new { @class = "whatever-class", @cols = 80, @rows = 10 })
或为 multi-line
类使用样式.
您也可以编写 EditorTemplate为此.
In ASP.MVC 3, how do I specify the columns and rows for a multiline EditorFor
(textarea)? I am using [UIHint("MultilineText")]
, but can't find any documentation on how to add attributes for the text area.
Desired HTML:
<textarea cols="40" rows="10"></textarea>
Relevant Part of my MVC 3 Model:
[UIHint("MultilineText")]
public string Description { get; set; }
Relevant Part of my Razor cshtml:
<div class="editor-field">
@Html.EditorFor(model => model.Description)
</div>
What I'm getting in View Source:
<div class="editor-field">
<textarea class="text-box multi-line" id="Description" name="Description"></textarea>
</div>
How do I set rows and columns?
解决方案
Use TextAreaFor
@Html.TextAreaFor(model => model.Description, new { @class = "whatever-class", @cols = 80, @rows = 10 })
or use style for multi-line
class.
You could also write EditorTemplate for this.
这篇关于如何在 ASP.MVC 中指定多行 Editor-For 的列和行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文