我想要完整的代码从 mvc 中的数据库填充菜单
我创建了一个带有数据库菜单的 mvc 应用程序。我想从第一次在母版页中加载菜单时开始渲染菜单。
请帮我..
I Created a mvc application with database menu. I want to render the menu from when it is loading first time in the master page.
please help me..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我从你的问题中了解到,你需要一个需要在每个页面上呈现的菜单。请按照下列步骤操作:
为您的菜单项创建一个控制器操作。如下所示:
<前><代码> [ChildActionOnly]
公共 ActionResult 样本ChildAction() {
var model = _myMenuRepo.GetAll();
返回视图(模型);
}
为此操作创建一个视图。看起来像下面这样:
<前><代码>@{
布局=空;
}
@foreach(模型中的var item) {- @item.MyDesc
}
从布局中调用此操作。代码应该如下所示:
本文也可以帮助您:
http ://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx
对于进一步的实现,您可能需要考虑缓存这部分您的应用程序:
http://www.tugberkugurlu.com/archive/donut-hole-caching-in-asp-net-mvc-by-using-child-actions-and-outputcacheattribute
As far as I understand from you question, you need a menu which you need to render on every page. Follow these steps :
Create a controller action for your menu item. Something like below :
Create a view for this action. Looks something like below :
Call this action from you layout. Code should look like something this :
This article also can help you :
http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx
For further implementations, you might wanna consider caching this part of your application :
http://www.tugberkugurlu.com/archive/donut-hole-caching-in-asp-net-mvc-by-using-child-actions-and-outputcacheattribute