asp.net-mvc-4razorcontrollerasp.net-mvc-partialviewrenderaction

How do I get MVC to find my controller path?


I am trying to call an action for a partial view in my _Layout view. If I place the action in the home controller, it works, but if I create a new controller StatusController, place the same child action method in it and call it from the _Layout view I get an error:

The Contoller path '/' was not found or does not implement IController.

from layout view _Layout.cshtml I call the action like so:

 @{Html.RenderAction("_GetforStatus", "StatusController");}

_GetforStatus() is the child action method inside the StatusController, as well as the name of the partial view.

How can i get ASP.NET MVC 4 to find my new controller?


Solution

  • You have to pass controller name without Controller postfix to make it work.The framework itself will exectue that Controller's action

    Write like this:

    @{Html.RenderAction{"_GetforStatus", "Status");}
    

    or you can also use this:

    @Html.Action("_GetforStatus","Status")