0

This is a fragment of view code from MVC tutorial

@model ContosoUniversity.Models.Student
...
Html.DisplayNameFor(model => model.LastName)
...
@foreach (var item in Model.Enrollments)
...

My silly question is why the model defined in the 1st statement as @model is used in the the second statement and it cannot be used in the the foreach loop of the last statement? Instead, the Model is used which is not declared in the view.

tereško
  • 58,060
  • 25
  • 98
  • 150
MBK
  • 525
  • 1
  • 8
  • 23
  • http://stackoverflow.com/questions/2896544/what-is-strongly-typed-view-in-asp-net-mvc , http://weblogs.asp.net/scottgu/asp-net-mvc-3-new-model-directive-support-in-razor – user2864740 Aug 06 '15 at 00:04

1 Answers1

0

@model is used to declare the strong type that the model is. Model is used to access the model itself.

Ala
  • 1,505
  • 1
  • 20
  • 36