【发布时间】:2015-08-08 19:44:05
【问题描述】:
我需要发送两个不同的Models,一个给Index view,另一个给_Layout.cshtml,我该怎么做?
我的HomeController:
[Route("")]
public ActionResult Index()
{
HomeViewModel model = new HomeViewModel();
model.A = _repoA.GetLatest(4);
model.B = _repoB.GetLatest(4);
model.C = _repoC.GetLatest(4);
return View(model);
}
我不喜欢使用 ViewBag、ViewData 和 ...,我正在寻找传递模型的方式与将模型传递给 Views 的方式相同。
【问题讨论】:
-
为什么不用模型创建局部视图并在布局中渲染。
-
听起来不错,但我更喜欢没有这个解决方案,有没有办法将模型直接发送到_layout?
-
请再看一遍问题,我想发给
index view和partial view两个人!!!
标签: asp.net-mvc-5 asp.net-mvc-partialview asp.net-mvc-layout