Reputation: 3199
I have the following in my razor view:
@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>
For some unknown magic, the default textarea value disappear.
Upvotes: 2
Views: 1716
Reputation: 13268
Bound elements can be defaulted using constructor of the model:
public class Product()
{
public string Description { get; set; }
//other properties
public Product() //the constructor
{
Description = "Put the default value here!";
//other default values
}
}
Upvotes: 0
Reputation: 4766
Textarea with asp-for attribute handle by TextAreaTagHelper and generated textarea with tagHelper not used from value that you set, for this you can use following syntax in ViewModel:
public class Product
{
...
public string Description{get; set;} => "Why is this default value disappearing?";
...
}
Upvotes: 1