【问题标题】:Multiline TextBox/Input Field In ASP.NET Core MVCASP.NET Core MVC 中的多行文本框/输入字段
【发布时间】:2017-09-30 05:23:21
【问题描述】:

为了制作多行输入字段,就像 ASP.NET MVC 我尝试了以下但在 ASP.NET Core MVC 中不起作用:

public class Post
{
   [DataType(DataType.MultilineText)]
   public string Body { get; set; }
}

在视图中:

<input asp-for="Body"  rows="40" class="form-control"/>

我们将不胜感激任何建议!

【问题讨论】:

    标签: html asp.net asp.net-core asp.net-core-mvc


    【解决方案1】:

    在 ASP.NET Core 工具库中有一个 open issue

    建议的解决方法是使用

    @Html.EditorFor(m => m.Body, additionalViewData: new { htmlAttributes = new { @class = "form-control" }})
    

    <textarea asp-for="Body" class="form-control"></textarea>
    

    【讨论】:

      【解决方案2】:

      还可以选择使用&lt;textarea&gt;-tag

      看起来像这样:

      <div class="form-group">
          <label asp-for="Body">Opmerkingen</label>
          <textarea asp-for="Body" class="form-control" text-wrap:normal" type="text" placeholder="Please add your experience here"></textarea>
          <span asp-validation-for="Body" class="text-danger"></span>
      </div>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-27
        • 2017-10-16
        • 1970-01-01
        相关资源
        最近更新 更多