Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RenderAction not finding action method in current controller in current area

I'm creating an ASP.NET MVC 2 (RTM) project that uses areas. The Index action of the Home controller of one area needs to use RenderAction to generate a sub-section of the page. The action called is also defined in the same Home controller. So the call should just be:

<% Html.RenderAction("List") %>

However, I get an exception:

A public action method 'List' was not found on controller 'RareBridge.Web.Areas.Events.Controllers.HomeController'.

Note that I'm not in the "Events" area! I'm in a completely different area. If I remove the "Events" home controller, then the exception still occurs but names a different controller (still not the one I want it to call).

I've also tried providing the controller name and area to the RenderAction method, but the same exception occurs. What is going on here?

BTW: I am using Autofac as my IoC container

like image 439
Andrew Davey Avatar asked Mar 15 '10 14:03

Andrew Davey


People also ask

What is the difference between HTML action and HTML RenderAction?

The difference between the two is that Html. RenderAction will render the result directly to the Response (which is more efficient if the action returns a large amount of HTML) whereas Html. Action returns a string with the result.

What is action method in controller?

Controllers process incoming requests using action methods. Action methods typically have a one-to-one mapping with user interactions. When a user enters a URL into the browser, the MVC application uses routing rules that are defined in the Global. asax file to parse the URL and to determine the path of the controller.

Can action methods be static?

- Action method cannot be a static method. ActionResult is a base class of all the result type which returns from Action method.

What is RenderAction in MVC?

RenderAction(HtmlHelper, String) Invokes the specified child action method and renders the result inline in the parent view. RenderAction(HtmlHelper, String, Object) Invokes the specified child action method using the specified parameters and renders the result inline in the parent view.


2 Answers

Probably action you call has filter attribute (i.e. AcceptVerbs) which doesn't match current request. Remove filters from "List" action and try again.

like image 66
3 revs Avatar answered Sep 28 '22 08:09

3 revs


Use the renderaction overload which takes routeValues as parameter and use the area property to redirect to a specific area:

f.i.

<% Html.RenderAction("Edit", module.Value, new { area = "Modules", id = module.Key }); %>
like image 21
Rody Avatar answered Sep 28 '22 10:09

Rody