1110
1110

Reputation: 6829

ASP MVC ChildActionOnly should have routing

I don't know if this is normal but should ChildActionOnly methods ask for route? For example

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

I render it like:

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

In debug I get on upper line:

No route in the route table matches the supplied values.

UPDATE

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

Upvotes: 5

Views: 2589

Answers (1)

RPM1984
RPM1984

Reputation: 73112

Yes it does.

All [ChildActionOnly] does is say that this action cannot be accessed via the URL (e.g a regular HTTP GET), rather it must be executed by Html.Action or Html.RenderAction. It's not a new HTTP request, but it still goes through the MVC request pipeline (controller/action selection via route values).

Upvotes: 5

Related Questions