Scenario
I am using Angular, purely for validation on my front-end, and MVC model binding
Example
<div ng-class="{'has-error': Contact.FirstName.$invalid}">
<input type="text"
name="@Html.NameFor(m => m.FirstName)"
id="@Html.IdFor(m => m.FirstName)"
value="@Model.FirstName"
ng-model="model.person.firstName"
required />
</div>
Problem
value
is populated by MVC on postback, but because model.person.firstName
is initially null
, the value is cleared when the document finishes loading, and angular has flushed all of it's magic into the view.
Question
How can I keep ng-model
(in order to keep validation working) and pre-populate the value
of the field?