ASP.NET MVC - How to set the default value in a strongly typed text article?

I am trying to get TextArea to have a default value.

<%: Html.TextAreaFor(Function(model) model.Description, 5, 10, New With {.Value = "Description: "})%>

This works correctly in TextBoxFor, but does not work inTextAreaFor

Am I missing something very obvious?

+2
source share
1 answer

You can specify the value of the Description property in the controller action when creating the model and pass this model to the view:

public ViewResult Create()
{
    var model = new MyPageModel() 
    {
        Description = "Description: ";
    }

    return View(model);
} 

In view:

<%: Html.TextAreaFor(model.Description) %>

Setting the value will not work, because the contents of the TextArea are indicated between the opening and closing tags, and not as an attribute.

+8
source

Source: https://habr.com/ru/post/1780461/


All Articles