当与 asp-for in razor-pages ASP.NET Core MVC 一起使用时,Textarea 不会显示其中的任何内容

Textarea won't show anything inside of it when used with asp-for in razor-pages ASP.NET Core MVC

HTML 标签 <input> 工作正常并显示其中的数据,但是当我使用 <textarea> 时它不起作用并且它可能不适用于 asp-for 但我仍然被迫使用 asp-for 因为我正在使用 .NET Core 构建网页。

这是出现故障的输出代码 (.cshtml)

@foreach (ComplaintManagement.Context.notesData note in ViewBag.getID)
                    {
                        <label>Subject</label>
                        <input required="required" class="form-control" asp-for="subject" value="@note.subject" />
                        <label>Summary</label>
                        <textarea class="form-control mb-2" asp-for="summary" rows="10">@note.summary</textarea>
                    }

如果我未能解释我的意思,希望我附上的图片对您有所帮助...

如需更多信息,请在评论区提问。

正常情况下:

<textarea name='awesome'>Default value</textarea>

但在你的情况下:

.NET Core 开发者使用asp-for必须在模型class中使用构造函数来设置默认值

示例:

public class Service()
{
    public string Description { get; set; }
    //other properties

    public Service() //the constructor
    {
      Description = "Put the default value here!";
      //other default values
     }
}

我自己找到了答案,而不是使用 asp-for 我使用了这个

<label>Summary</label>
<textarea class="form-control mb-2" rows="10" name="@Html.NameFor(m => m.summary)">@note.summary</textarea>

对文本区域使用 name="" 而不是 asp-for="" 解决了这个问题。