Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, can any one briefly explain what is the difference between @model and @Model in mvc (razor) ?
Posted

1 solution

1. Say suppose, you have a class

C#
public class person {
      public string Name {get;set;}
}



2. You are going to pass this class via a controller to the view and what you might do the the controller would be something similar

C#
public ActionResult Index()
{
 var _persons= _repo.GetPersons();
 return view(_persons);
}


3. The class you have a declarative section something like - This is to tell your view that you are passing a class and the type is person - we use @model syntax

C#
@model IEnumberable<person>



4. with in your view body, the class is available as "Model"

C#
@foreach(var x in Model>
{
<div>@x.name</div>
}



Hope this sheds some light for you

Regards
Bala
 
Share this answer
 
v2
Comments
Faisalabadians 21-Aug-13 9:37am    
Thanks for the explanation
Bala Selvanayagam 21-Aug-13 10:00am    
you are most wellcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900