views:

20

answers:

1

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?

+1  A: 

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.

Michael Shimmins
Great, this is what I was thinking too. It's an "Add" page so the model is null. Of course I can create an instance and pre-populate. I'll give it a try asap.
rockinthesixstring
works like a champ, thanks.
rockinthesixstring