ASP MVC ChildActionOnly应该有路由

时间:2012-02-07 22:57:14

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-routing

我不知道这是否正常,但ChildActionOnly方法是否需要路由? 例如

[ChildActionOnly]
        public PartialViewResult List(string countryCode, string cityName)
        {...
            return PartialView(model);
        }

我渲染它:

@{Html.RenderAction("List", "MyController", new { area = "MyArea", countryCode = ViewBag.CountryCode, cityName = ViewBag.CityName });}

在调试中我得到了上线:

  

路由表中没有路由与提供的值匹配。

更新

context.MapRoute("name",
                "",
                new { area = "MyArea", controller = "MyControlelr", action = "List", countryCode = UrlParameter.Optional, cityName = UrlParameter.Optional });

1 个答案:

答案 0 :(得分:5)

是的。

所有[ChildActionOnly]都表示无法通过URL访问此操作(例如常规HTTP GET),而必须由Html.ActionHtml.RenderAction执行。它不是新的HTTP请求,但它仍然通过MVC请求管道(通过路由值选择控制器/动作)。

相关问题