我想在一个页面上绑定两个模型..
使用此mehotd:https://www.codeproject.com/Articles/1108855/ways-to-Bind-Multiple-Models-on-a-View-in-MVC
我制作了一个控制器,它似乎工作得很好,除了一个,#34;列表"。它不能隐式地将类型List转换为Model:
public class MissiesController : Controller
{
// GET: Missies
public ActionResult GetMissieTombola()
{
MissieTombolaTagsViewModel MTTVM = new MissieTombolaTagsViewModel();
MTTVM.Tombola = GetTombolaModel();
MTTVM.Tags = GetTagsModel();
return View(MTTVM);
}
public MissiesTombola GetTombolaModel()
{
MissiesTombola bModel = new MissiesTombola()
{
Id = 1,
Omschrijving = "Tombola-item: Tas Douwe Egberts met zakje 75 gr. Dessertkoffie geschonken door Colruyt en een Indonesisch doekje met 1 BodyLotion en 1 DoucheGel",
Foto = "http://www.jeroenchristens.com/Koffie.png"
};
return bModel;
}
public List GetTagsModel()
{
List tModel = new List();
tModel.Add(new MissieTombolaTag() { Id = 1, TagId = 1, CatId = 1, OmschrijvingCat = "Koffie", icon = "http://www.jeroenchristens.com/Koffie.png" });
tModel.Add(new MissieTombolaTag() { Id = 1, TagId = 2, CatId = 2, OmschrijvingCat = "Keuken", icon = "http://www.jeroenchristens.com/Keukenitems.png" });
tModel.Add(new MissieTombolaTag() { Id = 1, TagId = 3, CatId = 3, OmschrijvingCat = "Badkamer", icon = "http://www.jeroenchristens.com/Badkameritems.png" });
return tModel;
}
}
public class List
{
internal void Add(MissieTombolaTag missieTombolaTag)
{
throw new NotImplementedException();
}
}
答案 0 :(得分:0)
类Tags
的属性MissieTombolaTagsViewModel
被声明为MissieTombolaTag
类型,但您尝试为其分配List
。将属性Tag
声明为List
类型。