Since the accepted answer is a link-only answer (and was removed), I thought I'd actually answer the question derived from Brad Wilson's Blog: ASP.NET MVC 2 Templates, Part 1: Introduction.
The model expressions are simple helpers which operate on the current model. The line DisplayForModel() is equivalent to DisplayFor(model => model).
TL;DR the same idea can be assumed for EditorFor(model => model)
and EditorForModel()
; these helper methods achieve the same thing. EditorForModel()
assumes the model expression is the @model
that was passed to the view.
Take the following models and view for example:
public class Person
{
public string Name {get; set;}
public Address MailingAddress {get; set;}
}
public class Address
{
public String Street {get; set;}
public String City {get; set;}
public String State {get; set;}
}
Create.cshtml
:
@model MyNamespace.Models.Person
/* So, you need an Editor for the Person model? */
@Html.EditorForModel()
/*the above is equivalent to @Html.EditorFor(model => model) */
/* you need to specify the Address property that the editor accepts? */
@Html.EditorFor(model => model.MailingAddress)