【问题标题】:cant set the size of a multi line text box mvc无法设置多行文本框 mvc 的大小
【发布时间】:2017-11-23 06:52:58
【问题描述】:

谁能告诉我为什么这行不通?无论我对列和行使用什么,文本框的大小始终相同

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

【问题讨论】:

    标签: asp.net-mvc textarea


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      或者您可以为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.

      【讨论】:

        猜你喜欢
        • 2015-04-22
        • 1970-01-01
        • 1970-01-01
        • 2012-01-13
        • 1970-01-01
        • 1970-01-01
        • 2014-09-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多