Reputation: 16466
Using the razor view engine, I have some code like the following:
@Html.TextAreaFor(model => model.Field, 20, 100, null)
How can I make this text area have a default value, i.e., what is normally in between <textarea>
and </textarea>
?
Upvotes: 2
Views: 1901
Reputation: 47387
The right way to do this is to populate the model from within the controller and send it to the view.
// 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);
Upvotes: 0
Reputation: 1137
It should work if you just populate the Field
property on the model with the default text. It will automatically insert the text when the markup is generated.
If you look at a view for edit, you see that this is how it works.
Upvotes: 3