0

I was reading this tutorial http://www.asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc3/cs/examining-the-edit-methods-and-edit-view

And found out this syntax

 @Html.EditorFor(model => model.Title)

I just could not understand this.

I mean what is model. Is this the model name in MVC 3 application. if it is then it should be incorrect because as seen from the tutorial it is not the name of the model in question.As can be seen from tutorial the name of the model is "Movie"

Any help will be appreciated

user786
  • 3,902
  • 4
  • 40
  • 72
  • 1
    It's a [lambda expression](https://msdn.microsoft.com/en-us/library/bb397687.aspx). `model` could be `foo` or `m` or whatever you want. – CodeCaster Oct 10 '15 at 17:54
  • @CodeCaster have u checked the tutorial. what is contained in `model`? – user786 Oct 10 '15 at 17:55

2 Answers2

1

Usually you one have one model per view. There are ways to have more models, but in that tutorial, for the sake of simplicity, they only have one. The model is being referenced by @ at the top: @model MvcMovie.Models.Movie and the name of the model is Movie. That's why the line you wrote works, because there's only one model in the view and it's possible to get it that way using nothing more than model.

Khaine775
  • 2,715
  • 8
  • 22
  • 51
1

I think in the example they are trying not to confuse issues early on by having to discuss lambdas.

The first line is @model MvcMovie.Models.Movie where the type of model used in the view is declared.

It possibly would be a better example had they written @Html.EditorFor(movie => movie.Title) - but as CodeCaster pointed, any value will do in the lambda. I tend to use @Html.EditorFor(x => x.Title). Have a play and see what style you prefer.

Neil Thompson
  • 6,356
  • 2
  • 30
  • 53