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
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.
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.
- Action method cannot be a static method. ActionResult is a base class of all the result type which returns from Action method.
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.
Probably action you call has filter attribute (i.e. AcceptVerbs) which doesn't match current request. Remove filters from "List" action and try again.
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 }); %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With