[英]Passing value from “select asp-for” to a “textarea” asp.net core razor
[英]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>
}
如果需要更多信息,请在评论部分询问。
我自己找到了一个答案,而不是使用 asp-for 我使用了这个
<label>Summary</label>
<textarea class="form-control mb-2" rows="10" name="@Html.NameFor(m => m.summary)">@note.summary</textarea>
对 textarea 使用name=""
而不是asp-for=""
解决了这个问题。
在正常情况下:
<textarea name='awesome'>Default value</textarea>
但在你的情况下:
使用 asp-for 的 .NET Core 开发人员必须使用模型类中的构造函数来设置默认值。
例子:
public class Service()
{
public string Description { get; set; }
//other properties
public Service() //the constructor
{
Description = "Put the default value here!";
//other default values
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.