如何使用控制器和操作在 asp.net mvc 2 中渲染部分视图?
<body>
<div id="header">
<div class="title">SPORTS STORE</div>
</div>
<div id="categories">
<% Html.RenderAction("Menu", "Nav"); %>
</div>
<div id="content">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
</body>
这是 Steven Sandersons 的书“Pro ASP.NET MVC Framework”中的示例代码。
此代码适用于 MVC V1 和 MvcContrib。它的作用是呈现“Nav:Controller”的“Menu()”视图。由于 ASP.NET MVC V2 包含 Partial() 和 RenderPartial() 功能,我尝试实现它,但此代码不起作用。我尝试以多种方式修改它,但似乎没有重载函数可以呈现部分视图,并将其作为参数: 1) 控制器名称 2)视图名称
我确信我不是第一个以这种方式实现 RenderAction() 的人,所以,必须有一个解决方法。请帮忙。
<body>
<div id="header">
<div class="title">SPORTS STORE</div>
</div>
<div id="categories">
<% Html.RenderAction("Menu", "Nav"); %>
</div>
<div id="content">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
</body>
This is a sample code from Steven Sandersons' book "Pro ASP.NET MVC Framework."
This code works with MVC V1 and MvcContrib. What it does, it renders a "Menu()" view of "Nav : Controller". Since ASP.NET MVC V2 includes the Partial() and RenderPartial() functionality, I tried to implement it, but this code doesn't work. I tried to modify it in several ways, but it seems there's no overload function that renders partial views, taking as parameters:
1) Controller name
2) View name
I'm sure I'm not the first person who is implementing RenderAction() in this way, so, there must be a workaround. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然我仍然不明白,这到底是如何工作的,为什么需要吸路由,以及路由的限制是什么。也许我稍后会做一些研究。
Although i still don't understand, how EXACTLY this works, why is suck route nessesary, and what are route's constraints. Maybe i will do some research later.
RenderAction
位于 MVC2 中(文档 在这里)。听起来您已经更改了代码以使用 RenderPartial 来代替,这是完全不同的。将其改回使用 RenderAction 就可以了。如果您的版本中没有它,也许您需要更新到最新的测试版?RenderAction
is in MVC2 (docs here). It sounds like you've changed your code to useRenderPartial
instead which is completely different. Change it back to useRenderAction
and you should be ok. If you don't have it in your version, perhaps you need to update to the latest beta?