0

Im having a problem getting donutcaching to work on an area i MVC3.

It seems that the "area"-attribute doesnt get passed along in the routeValueDictionary to the HtmlHelper Action-method in MvcDonutCaching.

I have a childaction that gets called like this: @Html.Action("Header", "Menu", true), and that works fine for all controllers that are not ind an area - but as soon it lies within an area, it cannot de found:

"The controller for path '/Indberetning/Administration/Index' was not found or does not implement IController."

I found out that the area doesnt get passed along to the exensionmethod that renders the action. Anyone has a solution for this? :)

AreaRegistration: public class IndberetningAreaRegistration : AreaRegistration { public override string AreaName { get { return "Indberetning"; } }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
          "Indberetning_DiscoHovedgruppe",
          "Indberetning/Disco/Hovedgrupper/{hovedgruppe}",
          new { controller = "Disco", action = "Hovedgrupper", hovedgruppe = UrlParameter.Optional }
      );
        context.MapRoute(
                      "Indberetning_FejlrapportIlOptaelling",
                      "Indberetning/Fejlrapport/IlOptaelling/il{iltype}/{fejltype}/side-{page}",
                      new { controller = "Fejlrapport", action = "IlOptaelling", page = 1 }
                  );


        context.MapRoute(
          "Indberetning_FejlrapportIpOptaelling",
          "Indberetning/Fejlrapport/IpOptaelling/ip{iptype}/{fejltype}/side-{page}",
          new { controller = "Fejlrapport", action = "IpOptaelling", page = 1 }
      );

        context.MapRoute(
         "Indberetning_Fejlrapport",
         "Indberetning/Fejlrapport/{action}/",
         new { controller = "Fejlrapport", action = "Fejlrapport" }
     );

        context.MapRoute(
          "Indberetning_VirksomhedUgyldigArbejdssted",
          "Indberetning/Virksomhed/UgyldigArbejdssted/{pnummer}/side-{page}/{tmetode}",
          new { controller = "Virksomhed", action = "UgyldigArbejdssted", page = 1, tmetode = UrlParameter.Optional }
      );

        context.MapRoute(
         "Indberetning_VirksomhedArbejdssted",
         "Indberetning/Virksomhed/Arbejdssted/{denr}/side-{page}/{tmetode}",
         new { controller = "Virksomhed", action = "Arbejdssted", page = 1, tmetode = UrlParameter.Optional }
     );

        context.MapRoute(
        "Indberetning_VirksomhedArbejdssteder",
        "Indberetning/Virksomhed/Arbejdssteder/side-{page}",
        new { controller = "Virksomhed", action = "Arbejdssteder", page = UrlParameter.Optional }
    );

        context.MapRoute(
           "Indberetning_DiscoDetaljer",
           "Indberetning/Disco/Detaljer/Hoveddiscogruppe-{id}/{jobStatus}",
           new { controller = "Disco", action = "Detaljer", jobStatus = UrlParameter.Optional }
       );
        context.MapRoute(
            "Indberetning_default",
            "Indberetning/{controller}/{action}/{id}",
            new { controller = "Forside", action = "Forside", id = UrlParameter.Optional }
        );
    }
}

The code runs fine without the outputcache implementation

tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

0

You need to use this overload of the Html.Action method:

public static MvcHtmlString Action(this HtmlHelper htmlHelper,
                                        string actionName,
                                        string controllerName,
                                        object routeValues,
                                        bool excludeFromParentCache)

And in you your case:

@Html.Action("Header", "Menu", new { Area = "AreaName" }, true)
haim770
  • 48,394
  • 7
  • 105
  • 133
  • Thanks for the quick reply :) Unfornunately, it doesnt work. I can see the area gets passed along just fine now, the funny thing is that when the code executes (after i've had the exception), the routevaluedictionary is emptied. It now has a length of 0 entries. Very strange – Dannie Walden Jan 02 '14 at 10:17
  • https://skydrive.live.com/#cid=CBE35DBDC1780EE6&id=CBE35DBDC1780EE6%219096&v=3 (an image showing that the area is passed along) https://skydrive.live.com/#cid=CBE35DBDC1780EE6&id=CBE35DBDC1780EE6%219097&v=3 (an image 1 singlestep further, now the routvaluedictionary is empty) – Dannie Walden Jan 02 '14 at 10:26
  • Add more code to the question, show the requested Controller.Action code, as well the AreaRegistration. – haim770 Jan 02 '14 at 10:26
  • What if you call the requested Action directly (not using `@Html.Action`)? – haim770 Jan 02 '14 at 10:29
  • I have updated the question :) The controller/action to be invoed is simple: public ActionResult Index() { return View(new AdministrationIndexViewModel()); } – Dannie Walden Jan 02 '14 at 10:32
  • It has a "ChildAction"-attribute, so i get "The action 'Header' is accessible only by a child request." – Dannie Walden Jan 02 '14 at 10:35
  • Oh my god! could it be that the "area"-attribute from the dynamic type entered as the routvaluedictionary in the Html.Action method is case-sensitive?. Changed the _new { Area = "AreaName" }_ to _new { area = "AreaName" }_ ..... That did the trick – Dannie Walden Jan 02 '14 at 11:35
  • Strange indeed. i doubt it was the reason for the problem. – haim770 Jan 02 '14 at 12:50