MVC3 ASP.NET - Strongly Typed View Fundamentals –“ you get out what you put in”

Strongly typed views are a really handy feature of the ASP.NET MVC framework. Aside from the obvious advantage of binding form data to a particular class or view model, the ability to extend this concept to templates/views with complex data types is real winner (WINNING!  as Mr Sheen would say).
The way it fundamentally works is based on what you put in is what you get out. What I mean by this is if for instance you have a complex type such as this example of a person:

Public Class Person

 String _name;
 String _age;
 Pet _pet;

 // gets & sets below..etc

If in the event you have a use case where you wanted to bind this particular class to a form (to create a “New” person), it would be pretty straight forward up until you got to the complex type Pet

What you would do is simply strongly type the person to a particular view and then within that view call a template or view file that is strongly typed to “Pet”. To assign a complex type to a template/view you simply utilise the html mvc helpers  Html.ControlFor. In this particular instance because you are not dealing with a simple html control like a text box you would use the:

Html.EditorFor(model => model.Pet, "Pet")  

Here you can see, you are putting an instance of the view model “pet” into the strongly typed view called “Pet” in order to get back a completely data filled view model when the original view form is submitted.

This is a very powerful way to simplify and encapsulate data in more complex and larger scale web sites.