[RESOLVED]Aspnet Mvc Html.Action with specified areaname still “no route in the route table matches the supplied values”

I was invoking a view using 

Html.Action

 in layout page.In this scene, my purpose is to generate a navigation. I have specified an “area” route value.However, it still turns out the “InvalidOperation” error, describing in “no route in the route table matches the supplied values”.

AdminController here contains a action named “_SideMenu”. AdminController.cs

public class AdminController : Controller
{
    //...
    public ActionResult _SideMenu()
    {
        var rootNavigations = navigationService.GetRootNavigations(PresentTarget.Admin);
        return View(rootNavigations);
    }
}

This is my AreaRegistration class. Html.Action should be not necessary to have a explicit route definition,as long as it can be inferred by area name,controller name,and action name. I’m sure about this beacause in the same project, others Html.Action invoking also didn’t define a route mapping specially for these actions and it still works.While I defined a “admin” controller in totally the same area and the same namespace and it doesn’t work.

That’s the reason that I didn’t define a mapping for _SideMenu. CommonAreaRegistration.cs

public class CommonAreaRegistration : AreaRegistration
{
    /// <summary>
    /// Area Name
    /// </summary>
    public override string AreaName
    {
        get { return "Common"; }
    }
    /// <summary>
    /// route registration
    /// </summary>
    /// <param name="context"></param>
    public override void RegisterArea(AreaRegistrationContext context)
    {
        //mappings...
        //**excluding mapping for _SideMenu** 
        //mappings...
    }
}

Here is how I invoked a action with specified area Route Value. _AdminLayout.cshtml

@Html.Action("_SideMenu","Admin",new {area = "Common"})

Though I have been succeed in define a mapping for _SideMenu.I don’t want to do this. I don’t expect visitors to access _SideMenu action directly through the mapping url which was defined for _SideMenu and this response is also unresonable.

Why is it not working? Thanks in advance.

ANSWER: 

 I review the  CommonAreaRegistration class again and I found a common route mapping defined like "Control/{action}".

I think this is just the reason that my code didn’t work.

In this way,I was wrong about Html.Action and It seems every action needs a specified or common route mapping.

Hi,

Try this

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Common_default",
                "Common/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional },
                new[] { "[Namespace of project].Areas.Common.Controllers" }
            );
        }

Hello,

CAN YOU POST YOUR ROUTE CONFIG  

because as far as i can see there is the root cause 

BR

Petar

Ah..thank you a lot. I review the  CommonAreaRegistration class again and I found a common route mapping defined like "Control/{action}".

I think this is just the reason that my code didn’t work.

In this way, It seems every action needs a specified or common route mapping.

Thanks again!

Thank you very much for your help!

Leave a Reply