首页 文章

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

提问于
浏览
0

谁能告诉我为什么这不起作用?无论我对cols和rows使用什么,文本框总是相同的大小

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

2 回答

  • 0

    您可以删除html属性,以下代码应该可以工作 .

    @Html.TextAreaFor(model => model.Report.EmailMessage, new { @class = "form-control", @cols = 100, @rows = 20 })
    
  • 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.

相关问题