如何发送模型_Layout.cshtml(我需要再派模型索引视图太) [英] How to send Model to _Layout.cshtml (I need to send another model to Index view too)
本文介绍了如何发送模型_Layout.cshtml(我需要再派模型索引视图太)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要发送2个不同的模式
,一个索引视图
,另一种为 _Layout.cshtml
,我该怎么办呢?
I need to send 2 different Models
, one to Index view
and another one to _Layout.cshtml
, how I can do it?
我的的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 code>&安培; ......,我在寻找传递模型相同的方式,我们通过模型
查看
。
I don't like using ViewBag
, ViewData
& ..., I'm looking for passing the model in same way as we passing model to Views
.
推荐答案
您可以将这个在布局加载每次的部分... pretty加载有用的一块动态菜单或构件的每一页上。
You can place this in your Layout to load a partial each time... Pretty useful for loading in a piece of a dynamic menu or a widget on each page.
随着这条线在你的布局你可以做你的索引页,你通常会。
Along with this line in your layout you can just do your Index page as you normally would.
@{ Html.RenderAction("_widget", "Home"); }
这篇关于如何发送模型_Layout.cshtml(我需要再派模型索引视图太)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文