Html.RenderAction导致"在路由表中没有路由匹配所提供的值" [英] Html.RenderAction causes "No route in the route table matches the supplied values"

查看:221
本文介绍了Html.RenderAction导致"在路由表中没有路由匹配所提供的值"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以这种方式使用Html.RenderAction在ASP.NET MVC 2 RC2:

在菜单的Controler:

  [ChildActionOnly]
公众的ActionResult ContentPageMenus()
{
     VAR菜单= _contentPageMenuRepository.GetAll()WithCulture(的CurrentCulture)。
     返回PartialView(菜单);
}
 

而在我的索引视图(Home控制器的Index操作):

 <%Html.RenderAction(ContentPageMenus,ContentPageMenu);%GT;
 

不过,我总是得到这样的错误信息: 在路由表中没有路由匹配所提供的值。

解决方案

MVC期货用来让那没有路由的行动渲染

。这在ASP.NET MVC2改变。

如果你想RenderAction工作,想隐藏自己的路线,以便它不是公开访问。

  1. 添加路由的行动 globals.asax.cs
  2. 装饰用 [ChildActionOnly] 属性的作用。

I'm trying to use Html.RenderAction in ASP.NET MVC 2 RC2 in this way:

In Menu Controler:

[ChildActionOnly]
public ActionResult ContentPageMenus()
{
     var menus = _contentPageMenuRepository.GetAll().WithCulture(CurrentCulture);
     return PartialView(menus);
}

And in my Index view (for Index action of Home controller):

 <% Html.RenderAction("ContentPageMenus", "ContentPageMenu");%>

But I always get this error message: No route in the route table matches the supplied values.

解决方案

MVC Futures used to allow rendering of actions that had no routes. This has changed in ASP.NET MVC2.

If you want RenderAction to work and would like to hide your route so its not publicly accessible.

  1. Add a route for your action in globals.asax.cs.
  2. Decorate your action with the [ChildActionOnly] attribute.

这篇关于Html.RenderAction导致&QUOT;在路由表中没有路由匹配所提供的值&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆