0

Using BetterCMS 2.0.6.192 directly from NuGet. Brand new c# project.

I've been through the setup multiple times but cannot get a Server Widget to call custom Controller/View code.

I am attempting to create a custom server widget. I have the Phonebook.cshtml in the View/Widgets folder and registered as as Widget on a page in the site. This widget view will render with some simple html but when I try to Post or render a partial view I get an error "No route in the route table matches the supplied values".

Within the Phonebook.cshtml widget I have added

@{ Html.RenderAction("Index", "Phonebook", new {Area = ""}); }

but the partial view is not found. The error message, seen on the page with the widget is,

"Error rendering view "~/Views/Widgets/Phonebook.cshtml": No route in the route table matches the supplied values.".

I have a PhonebookController in the /Controllers folder in the /Views folder I have an Index.cshtml. While debugging the Index view is never fired.

I have also tried adding

@{ Html.RenderAction("Index", "Phonebook", new { Area = "Phonebook" }); }

to the /Views/Widgets/Phonebook.cshtml. I have /Areas/Phonebook/Controllers/PhonebookController.cs and /Areas/Phonebook/Views/Index the Index action is never fired.

I think it might have to do with routing. In the PhonebookAreaRegistration.cs file I have

context.MapRoute( "Phonebook_default", "Phonebook/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional } );

In the /App_Start/RouteConfig.cs I have commented out the default routing as instructed in the docs.

Help.

This is a cross posted in Better CMS forum, not sure how much traffic that forum gets anymore. http://www.bettercms.com/support/widgets-and-modules/struggling-with-server-widget/

Brett
  • 786
  • 1
  • 8
  • 10

1 Answers1

0

Rookie mistake. Forgot to register Routes in Global.asax.cs file.

Old Code- Does not work:

protected void Application_Start()
{
    cmsHost = CmsContext.RegisterHost();
    cmsHost.OnApplicationStart(this);
}

New Code- Works:

   protected void Application_Start()
   {
       cmsHost = CmsContext.RegisterHost();

       AreaRegistration.RegisterAllAreas();
       FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
       RouteConfig.RegisterRoutes(RouteTable.Routes);

       cmsHost.OnApplicationStart(this);
   }
Brett
  • 786
  • 1
  • 8
  • 10