How to route to and access custom plugin views?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 years ago
Dear all,

following the advice given here  in the forum, I created my first NopCommerce plugin.  
The plugin was listed among the other plugins in the administration panel. Installation went well, too.

However, I am having trouble accessing my custom plugin's views.
Either the page could not be found, with the application returning the following message:

Page not found
The page you requested was not found, and we have a fine guess why.

If you typed the URL directly, please make sure the spelling is correct.
The page no longer exists. In this case, we profusely apologize for the inconvenience and for any damage this may cause.


or else the application threw a "real" exception, e.g (abridged stack trace).

System.InvalidOperationException
  HResult=0x80131509
  Message=The view 'Index' was not found. The following locations were searched:
/Themes/DefaultClean/Views/CustomPlugin/Index.cshtml
/Themes/DefaultClean/Views/Shared/Index.cshtml
/Plugins/Nop.Plugin.Misc.CustomPlugin/Views/CustomPlugin/Index.cshtml
/Views/CustomPlugin/Index.cshtml
/Views/Shared/Index.cshtml
/Pages/Shared/Index.cshtml
  Source=Microsoft.AspNetCore.Mvc.ViewFeatures
  StackTrace:
   at Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable`1 originalLocations)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.<ExecuteAsync>d__7.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[...]
  This exception was originally thrown at this call stack:
    [External Code]
    Nop.Services.Authentication.AuthenticationMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext) in AuthenticationMiddleware.cs
    [External Code]
    Nop.Services.Installation.InstallUrlMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext, Nop.Core.IWebHelper) in InstallUrlMiddleware.cs
    [External Code]
    Nop.Services.Common.KeepAliveMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext, Nop.Core.IWebHelper) in KeepAliveMiddleware.cs
    [External Code]
    Nop.Web.Framework.Infrastructure.Extensions.ApplicationBuilderExtensions.UseNopExceptionHandler.AnonymousMethod__2_1(Microsoft.AspNetCore.Http.HttpContext) in ApplicationBuilderExtensions.cs
    [External Code]


I would also like to add that - based on those plugins already present in the application - my `RouteConfig.cs` is as follows:

/// <summary>
        /// Register routes
        /// </summary>
        /// <param name="endpointRouteBuilder">Route builder</param>
        public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
        {
            endpointRouteBuilder.MapControllerRoute(
                CustomPluginDefault.IndexRoute,
                "Plugins/CustomPlugin/Index",
                new {controller = "CustomPlugin", action = "Index"}
            );
            
            endpointRouteBuilder.MapControllerRoute(
                CustomPluginDefault.OverviewRoute,
                "Plugins/CustomPlugin/Overview",
                new { controller = "CustomPlugin", action = "Overview" }
            );

        }

        /// <summary>
        /// Gets a priority of route provider
        /// </summary>
        public int Priority => 0;


My `CustomPluginDefault.cs` file looks like this (also modified based on already existing similar files)


class CustomPluginDefault
    {
        public static string TRACKING_VIEW_COMPONENT_NAME => "WidgetsCustomPlugin";

        public static string IndexRoute => "Plugin.Misc.CustomPlugin.Index";
        public static string OverviewRoute => "Plugin.Misc.CustomPlugin.Overview";

    }


Without going deeper into the actual code, I would like to briefly explain what I intend to do here. Basically, the `Index` view
provides a form that needs to be filled out, the second view displays the results based on the entries made in `Index`.

Rephrasing my question:
How would I need to change any routing in any file(s) to properly display both the `Index` and `Overview` in the standard shop user interface?

Thanks a mil in advance for your suggestions, not quite sure what I am missing here.

Kind regards

Chris
3 years ago
While further researching the issue, I came across this post here in the forum, which linked to this blog post. This actually relates quite well to what I am trying to achieve. However both posts are quite old and I was wondering if there was an updated example for NetCore and NC 4.30 out there somewhere.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.