I'm trying to make a TextArea have a default value.
<%: Html.TextAreaFor(Function(model) model.Description, 5, 10, New With {.Value = "Description: "})%>
This works properly in a TextBoxFor
but doesn't work in a TextAreaFor
Am I missing something very obvious?
You can specify the value for Description property in the controller action when creating the model, and pass that model to the View:
public ViewResult Create()
{
var model = new MyPageModel()
{
Description = "Description: ";
}
return View(model);
}
In the view:
<%: Html.TextAreaFor(model.Description) %>
Setting the value won't work as the contents of a TextArea are specified between the opening and closing tags, not as an attribute.
来源:https://stackoverflow.com/questions/3655033/asp-net-mvc-how-can-i-set-the-default-value-in-a-strongly-typed-textarea