asp.net-mvcasp.net-mvc-routingumbraco6

Html.Action() results in "No route in the route table matches the supplied values"


This issue has been discussed many times, but I haven't found a resolution for my particular case.

In one of my Umbraco (6) views I am calling a controller method by using

@Html.Action("Index", "CountryListing");

This results in the "no route in the route table" exception.

I have been fiddling around with the RegisterRoutes method to no avail. I wonder if it is even used as the site still functions when I empty the RegisterRoutes method. This is what it looks like now:

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }

I have also tried adding an empty "area" to the call like this

@Html.Action("Index", "CountryListing", new {area: String.Empty});

I am using @Html.Action statements in other places and they DO work, so I do understand why some of them work and others don't, but the main problem now is getting my country listing action to work.


Solution

  • You can solve this by doing the following

    1. Make sure your Controller is extending Umbraco's SurfaceController
    2. Name it YourName*SurfaceController*
    3. Add the [PluginController("CLC")] 'annotation' (I am from Java) to your controller. CLC stands for CountryListController. You can make up your own name of course.
    4. Add the PluginController name (CLC) to the Html.Action call as a "Area" parameter.

    My controller:

    [PluginController("CLC")]
    public class CountryListingSurfaceController : SurfaceController
    {
        public ActionResult Index()
        {
           var listing = new CountryListingModel();
    
           // Do stuff here to fill the CountryListingModel
    
           return PartialView("CountryListing", listing);
        }
    }
    

    My partial view (CountryListing.cshtml):

    @inherits UmbracoViewPage<PatentVista.Models.CountryListingModel>
    
    @foreach (var country in Model.Countries)
    {
        <span>More razor code here</span>  
    }
    

    The Action call:

    @Html.Action("Index", "CountryListingSurface", new {Area= "CLC"})