无法设置多行文本框的大小mvc

时间:2017-06-20 16:03:35

标签: asp.net-mvc textarea

任何人都可以告诉我为什么这不起作用?无论我用什么用于cols&行,文本框总是相同的大小

@ Html.TextAreaFor(model => model.Report.EmailMessage,new {htmlAttributes = new {@class =" form-control",@ cols = 100,@rows = 20}})

2 个答案:

答案 0 :(得分:0)

您可以删除html属性,以下代码应该有效。

@Html.TextAreaFor(model => model.Report.EmailMessage, new { @class = "form-control", @cols = 100, @rows = 20 })

答案 1 :(得分:0)

或者您可以对TextAreaFor使用以下重载:

public static MvcHtmlString TextAreaFor<TModel, TProperty>(
    this HtmlHelper<TModel> htmlHelper,
    Expression<Func<TModel, TProperty>> expression,
    int rows,
    int columns,
    object htmlAttributes
)

产:

@Html.TextAreaFor(model => model.Report.EmailMessage, 20, 100, new { @class = "form-control" })

Relevant link to MSDN article.