Override Existing Controller & Action in Nop Version 4.0

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

You can play with Priority, set it -100 or 10 or 1 and check debug point is calling or not on restart application.
6 years ago
rajupaladiya wrote:
Hello,

You can play with Priority, set it -100 or 10 or 1 and check debug point is calling or not on restart application.


Hi.
Thanks again for your reply.
I set priority in RouteProvider to -100 or 10 or 1. but yet can't work.
6 years ago
My Dependency Register is:


    public class CustomDependencyRegister : IDependencyRegistrar
    {
        private const string ContextName = "nop_object_context_Sample";
        public int Order => 999;

        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {                
            builder.RegisterType<CustomHomeAdminController>)
.As<Nop.Web.Areas.Admin.Controllers.HomeController>();
        }
    }
6 years ago
Hi every body.
Finally, this route resolve my problem:

            routeBuilder.MapAreaRoute(
                name: "Nop.Plugin.Misc.Sample.CustomHomeAdmin",
                areaName: AreaNames.Admin,
                template: "Admin/{controller=CustomHomeAdmin}/{action=CustomIndex}/{id?}");


But notice its performance lags!

For redirect to custom view,solution is:

return View("~/Plugins/Misc.Sample/Views/CustomHomeAdmin/CustomIndex.cshtml", model);


Other issue is that,Whether there is a way that the instead of using above code,
This code is used?

return View("CustomIndex", model);


My CustomViewLocationExpander is:

    public class CustomViewLocationExpander : IViewLocationExpander
    {
        public void PopulateValues(ViewLocationExpanderContext context)
        {
        }

        public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
        {


                viewLocations = new[] {
                            $"~/Plugins/Misc.Sample/Views/{{1}}/{{0}}.cshtml",
                            $"~/Plugins/Misc.Sample/{{0}}.cshtml"
                        }
                        .Concat(viewLocations);

            return viewLocations;
        }


CustomStartup:

    public class CustomStartup : INopStartup
    {
        #region Implementation of INopStartup
        public void ConfigureServices(IServiceCollection services, IConfigurationRoot configuration)
        {
            //themes support
            services.Configure<RazorViewEngineOptions>(options =>
                                                       {
       options.ViewLocationExpanders.Add(new CustomViewLocationExpander());
                                                       });            
        }

        public void Configure(IApplicationBuilder application)
        {
            
        }

        public int Order => 0;
        #endregion
    }


When I Use this:

return View("CustomIndex", model);

Cause an error to be,

But this code works:

return View("~/Plugins/Misc.Sample/Views/CustomHomeAdmin/CustomIndex.cshtml", model);


Where is my problem? Please advice me.

Thanks

[Best Regards]
5 years ago
I found a solution to this. I explained my answer in detail here https://www.nopcommerce.com/boards/t/50136/overriding-controller-and-view-in-nopcommerce-40.aspx#205182
5 years ago
mshenoy83 wrote:

Thank you for sharing.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.