Using Hthml.RenderAction to call action from a base controller

I have an action in my "BaseController" which all other controllers inherit from. When my view has Html.RenderAction("CommonAction"); it throws the error that there is no route value in the route table for the action. What do I have to do to get the action
to fire? I am using Attribute Routing

Hi Eagle_f90,

Thanks for your post.

According to your description,

Eagle_f90

throws the error that there is no route value in the route table for the action.

  • For that, You have to select the RouteConfig.cs inside the App_Start Folder.
  • After that call MapMvcAttributeRoutes is as below:
public class RouteConfig


    {

        public static void RegisterRoutes(RouteCollection routes)

        {

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

       routes.MapMvcAttributeRoutes();//Attribute Routing

            //Convention-based Routing

            routes.MapRoute(

                name: "Default",

                url: "{controller}/{action}/{id}",

                defaults: new { controller = "Home", action = "Index",

                                id = UrlParameter.Optional }

            );

        }

    }
  • To enable Attribute Routing,You have to call MapMvcAttributeRoutes on RouteConfig File.
  • If you want, You can keep the Convention-based Routing also with the same file is as above.
  • But routes.MapMvcAttributeRoutes();
    Should configure before the Convention-based Routing.

Hope this can be helpful.

Best Regards,

Eileen

I have attribute routing enabled and working fine. For some reason MVC is not generating/finding the route for this action only.

Leave a Reply