Próbuję wyświetlić listę, którą zrobiłem w moim widoku, ale nadal otrzymuję: "Element modelu przekazany do słownika jest typu" System.Collections.Generic.List 1[System.String]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1 [Tabele. Models.Teams] "."Wyświetlanie listy w widoku MVC
My Kontroler:
public class HomeController : Controller
{
Teams tm = new Teams();
public ActionResult Index()
{
var model = tm.Name.ToList();
model.Add("Manchester United");
model.Add("Chelsea");
model.Add("Manchester City");
model.Add("Arsenal");
model.Add("Liverpool");
model.Add("Tottenham");
return View(model);
}
Mój model:
public class Teams
{
public int Position { get; set; }
public string HomeGround {get; set;}
public string NickName {get; set;}
public int Founded { get; set; }
public List<string> Name = new List<string>();
}
Moim zdaniem:
@model IEnumerable<Standings.Models.Teams>
@{
ViewBag.Title = "Standings";
}
@foreach (var item in Model)
{
<div>
@item.Name
<hr />
</div>
}
Każda pomoc będzie mile widziane :)
chcesz przekazać zbiór zespołów lub listę nazwisk zespołu (czego jesteś przejazdem)? –
Dlaczego obiekt drużyny piłkarskiej nosi nazwę "Drużyny" (liczba mnoga) i dlaczego jedna drużyna ma wiele imion? Myślę, że musisz uważnie przyjrzeć się modelowi! –
Wypróbuj moją odpowiedź poniżej. Twój model nie jest zaimplementowany poprawnie. –