Your action method considers the model type as List<string> . But, in your opinion, you are waiting for IEnumerable<Standings.Models.Teams> . You can solve this problem by changing the model in your opinion to List<string> .
But a better solution would be to return IEnumerable<Standings.Models.Teams> as a model from your action method. Then you should not change the type of model in your view.
But , in my opinion, your models are incorrectly implemented. I suggest you change it as:
public class Team { public int Position { get; set; } public string HomeGround {get; set;} public string NickName {get; set;} public int Founded { get; set; } public string Name { get; set; } }
Then you should change your action method as follows:
public ActionResult Index() { var model = new List<Team>(); model.Add(new Team { Name = "MU"}); model.Add(new Team { Name = "Chelsea"}); ... return View(model); }
And, your opinion:
@model IEnumerable<Standings.Models.Team> @{ ViewBag.Title = "Standings"; } @foreach (var item in Model) { <div> @item.Name <hr /> </div> }
source share