MikeTWebb
MikeTWebb

Reputation: 9279

MVC3 Default value for HTML.TextAreaFor

I have an html.TextArea helper that I'd like to set a default.

@Html.TextAreaFor(model => model.CompletionCriteria,
                                  new { rows = 5, cols = 70, @class = "celltext2", 
                                      @Value = ViewBag.CompletionCriteria,
                                      @Text =  ViewBag.CompletionCriteria })

The controller is setting the ViewBag.CompletionCriteria variable by querying the DBContext to get the default vaule for this given TextArea. The TextArea Value and Text properties are being set correctly, so the ViewBag is good, however the data doesn't display in the TextArea. I'm sure I'm just missing a property setting. Any ideas?

Upvotes: 1

Views: 6432

Answers (2)

hasanaydogar
hasanaydogar

Reputation: 905

In controller

Phone = model.UserPhoneNumber

In HTML

 @Html.TextBoxFor(m => m.MobilePhone, new { @class = "form-control", @Value =Viewbag.UserPhoneNumber, data_mask = "phone" })

For Custom Attributes you can use like data_mask sample

it will render like data-mask ="phone"

Upvotes: 0

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93444

Remove the @Value and @Text attributes. It will automatically populate it, assuming it's set correctly and you're not using a strongly typed model. make sure it's spelled correctly in both your View and Controller.

Upvotes: 2

Related Questions