Razor textarea的默认值不为';行不通
我的观点如下:Razor textarea的默认值不为';行不通,razor,asp.net-core,asp.net-core-tag-helpers,Razor,Asp.net Core,Asp.net Core Tag Helpers,我的观点如下: @model Product <form ...> ... <div class="form-group"> <label asp-for="Description"></label> <textarea asp-for="Description" class="form-control" cols="20" rows="3">Why is this defaul
@model Product
<form ...>
...
<div class="form-group">
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control" cols="20" rows="3">Why is this default value disappearing?</textarea>
</div>
...
</form>
@型号产品
...
为什么这个默认值会消失?
...
对于一些未知的魔法,默认的textarea值消失。textarea with asp用于textarea tagHelper的属性句柄,以及根据您设置的值生成的textarea with tagHelper未使用,为此,您可以在ViewModel中使用以下语法:
public class Product
{
...
public string Description{get; set;} => "Why is this default value disappearing?";
...
}
可以使用模型的构造函数默认绑定元素:
public class Product()
{
public string Description { get; set; }
//other properties
public Product() //the constructor
{
Description = "Put the default value here!";
//other default values
}
}
产品
中的说明
字段是否为空值?尝试加载没有如下描述的textarea为什么默认值会消失?
这将显示默认值。