ASP.NET MVC 3 TextArea默认内容

时间:2011-06-26 15:17:23

标签: asp.net-mvc asp.net-mvc-3

使用剃刀视图引擎,我有一些代码如下:

@Html.TextAreaFor(model => model.Field, 20, 100, null)

如何使此文本区域具有默认值,即<textarea></textarea>之间的通常值?

2 个答案:

答案 0 :(得分:3)

如果您只使用默认文本填充模型上的Field属性,它应该可以工作。它会在生成标记时自动插入文本。

如果您查看要编辑的视图,您会看到它的工作原理。

答案 1 :(得分:0)

执行此操作的正确方法是从控制器中填充模型并将其发送到视图。

// create a new model object
MyViewModel model = new MyViewModel();

// populate the "Field" property in said object
model.Field = "this is my field text";

// send the pre-populated model to the veiw
return View(model);
相关问题