IT:AD:ASP.NET:MVC:Views:Forms:Binding
Summary
The traditional mechanism of binding in a View is handled by
- defining a Model for the View, using the
@modelkeyword - using either
HtmlHelper.EditorFororHtmlHelper.DisplayFor, depending on whether read only or read/write is desired:
The basics being Example:
@using Examples.Models
@model MyModel
@using Html.BeginForm() {
<callout icon="true" type="style="border:solid 2px red;"">
@Html.EditorFor(m => m.AccountViewModels);
</callout>
<input type="submit"/>
}
The HtmlHelper (IT:AD:ASP.NET:MVC:Views:HtmlHelpers) will combine the following
- Model
- ModelState
- ModelMetadata
to output Html to the current Response stream.
ViewModel versus ViewData
Editors
Out of the box, you use EditorFor and DisplayFor methods to bind to the Model.
But that's just the tip of the iceberg of the control you can have over the output: IT:AD:ASP.NET:MVC:Views:Forms:Editors