ASP.NET MVC - How can I set the Default Value in a Strongly Typed TextArea?

[亡魂溺海] 提交于 2019-12-01 10:42:56

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!