我需要在我的視圖中有2 models
。但由於我們只能添加1個視圖,我採取了以下方法;嘗試將多個模型添加到視圖時出錯提示
@model Tuple<My.Models.Mod1,My.Models.Mod2>
@Html.DropDownListFor(m => m.Item2.humanKind,Model.Item2.allHuman)
@Html.TextBoxFor(m => m.Item1.food)
但是,我最終得到的是以下錯誤;
The model item passed into the dictionary is of type 'My.Models.Mod2', but this dictionary requires a model item of type 'System.Tuple`2[My.Models.Mod1,My.Models.Mod2]'.
這是什麼,我該如何解決這個問題?
UPDATE
public ActionResult Index()
{
var model2 = new Mod2 { allHuman = allHumans() };
var model1 = new Mod1(); // JUST NOW I ADDED THIS, BUT IT DOESn't WORK
return View(model1,model2);
}
發佈您的控制器代碼。 – 2013-02-18 21:54:29
您在這個'@model Tuple'代碼行中的答案。 –
sigod
2013-02-18 21:56:21
對不起@EricJ。我誤解了,你是對的。 – 2013-02-18 21:58:08