ASP.NET MVC - 我如何可以设置一个强类型的文本区域的默认值? [英] ASP.NET MVC - How can I set the Default Value in a Strongly Typed TextArea?
本文介绍了ASP.NET MVC - 我如何可以设置一个强类型的文本区域的默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做一个TextArea有一个默认值。
I'm trying to make a TextArea have a default value.
<%: Html.TextAreaFor(Function(model) model.Description, 5, 10, New With {.Value = "Description: "})%>
这正常工作在 TextBoxFor
但不工作 TextAreaFor
This works properly in a TextBoxFor
but doesn't work in a TextAreaFor
我缺少的东西很明显?
推荐答案
您可以在控制器动作创建模型时指定说明属性的值,而模型传递给视图:
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);
}
在该视图:
<%: Html.TextAreaFor(model.Description) %>
设置为是在开始和结束标记之间指定一个TextArea的内容,而不是作为一个属性值将无法工作。
Setting the value won't work as the contents of a TextArea are specified between the opening and closing tags, not as an attribute.
这篇关于ASP.NET MVC - 我如何可以设置一个强类型的文本区域的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文