【发布时间】:2011-04-23 05:34:55
【问题描述】:
我有一个使用 ASP.net MVC3 的网络项目。我的项目中有一个子动作。我用
<% Html.RenderAction("Navigator", "Application");%>
调用共享操作。但我发现如果我当前的 url 是“localhost/application”,它会抛出异常“路由表中的路由与提供的值不匹配”。但是当当前 url 是“localhost/application/index”时,它可以正常工作。索引是我的路由配置中的默认操作,如下所示:
public static void RegisterRoutesTo(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
//routes.IgnoreRoute("{*chartName}", new { chartName = @"(.*)?Chart.aspx" }); //ignore request for charting request
routes.Ignore("{*pathInfo}", new { pathInfo = @"^.*(ChartImg.axd)$" });
routes.MapRoute(
"Default", // Route name
"{controller}/{id}/{action}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new { httpMethod = new HttpMethodConstraint("GET", "POST") } // Allowed http methods
);
}
请注意,我切换了默认 ID 和操作位置。我看到 mvc 可以在使用“Html.ActionLink(...)”时删除 url 中的默认控制器和操作名称。而且我不喜欢在我的视图中使用显式的 url 字符串。如何让它发挥作用?
我的动作代码很简单:
[ChildActionOnly]
public ActionResult Navigator()
{
return PartialView(appFacility.GetAll());
}
非常感谢。
【问题讨论】:
标签: asp.net-mvc-3