Whats the difference between the @model applicationname.models.modelname and @model Ienumerable<appl

Posted by Swappy_Gaj under ASP.NET MVC on 1/19/2015 | Points: 10 | Views : 1038 | Status : [Member] | Replies : 1
Whats the difference between the

@model applicationname.models.modelname and @model IEnumerable<applicationname.models.modelname>




Responses

Posted by: Sheonarayan on: 1/19/2015 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
@model applicationname.models.modelname is the actual class name where you can access the model property using @Model.PropertyName or @Html.LabelFor(model => model.PropertyName)

@model IEnumerable<applicationname.models.modelname> is the collection of models; to access properties of the model you need to loop through the collection like below

@foreach (var item in Model) {
@Html.DisplayFor(modelItem => item.PropertyName)
}

Hope this helps.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Swappy_Gaj, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response