c# - ASP.NET - Model does not exist -
i'm having problems using foreach , html list in view. controller calls service returns ienumerable of number of items, , i'm trying display these items html list in view.
however, i'm getting "cs0103: name 'model' not exist in current context" on line 7 of view. far i'm aware i've got right syntax displaying things model.
what going wrong?
i have model this:
public class newsitem { public datetime publishdate { get; set; } public string title { get; set; } public string description { get; set; } public string content { get; set; } }
and controller this:
public actionresult index() { newsreader newsreader = new newsreader(); var newsitems = newsreader.getnewsitems(); return view(newsitems); }
and view:
@model ienumerable<site.services.news.newsitem> @{ layout = "~/views/shared/_layout.cshtml"; } @foreach(var item in model) { <ul> <li>@html.displayfor(m => model.title)</li> </ul> }
you should capitalize "model" , use "item" in displayfor:
@foreach(var item in model) { <ul> <li>@html.displayfor(m => item.title)</li> </ul> }
Comments
Post a Comment