我有一个html帮助器:
@Html.EditorFor(model => model.Description)
但是对于我的模型属性中的数据来说太小了。描述是一个1000个字符的字符串。我需要用户能够输入几行文本,并将其包装在HTML对象中。我该怎么做呢?
Try
Html.TextAreaFor(model => model.Description, new {@cols="80" , @rows="4" })
使用说明:
@Html.TextAreaFor(model => model.Description)
// or a full option-list is:
@Html.TextAreaFor(model => model.Description,
rows, // the rows attribute of textarea for example: 4
columns, // the cols attribute of textarea for example: 40
new { }) // htmlAttributes to add to textarea for example: @class = "my-css-class"
注意:你可以用null
代替new { }
代替htmlAttributes
,但不建议这样做!强烈建议使用代表new object
的空白new { }
-
您可以使用EditorFor
,但在这种情况下,最好定义自己的EditorTemplate来呈现您的TextArea,使用TextAreaFor
或任何需要的
TextAreaFor
和EditorFor
之间的主要区别是,如果我已经很好地理解了一切是如何工作的,当使用EditorFor时,模板被考虑进去,而当使用TextAreaFor
时,你选择用于渲染的HTML输入。
模板看起来很有趣,我刚刚开始钻研写我自己的模板。
听起来像是Html.TextAreaFor.