Struggling with server Widget

  1. Avatar of Brett

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

    Here is my struggle. 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 a form or show a partial view I get an error "o 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.

    Brett

  2. Avatar of Brett

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

    Old File - Does not work

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

    New File - Works

       protected void Application_Start()
        {
            cmsHost = CmsContext.RegisterHost();
    
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
    
            cmsHost.OnApplicationStart(this);
        }
    
* Mandatory
* Mandatory
* Mandatory

Verify that you are human