【问题标题】:override view from plugin NopCommerce 4.3从插件 NopCommerce 4.3 覆盖视图
【发布时间】:2021-01-15 15:30:12
【问题描述】:

我想覆盖送货方式页面的视图。我尝试了所有变体,但没有任何效果。 请帮帮我。提前致谢

【问题讨论】:

    标签: c# content-management-system nopcommerce


    【解决方案1】:

    要覆盖 NopCommerce 中的视图,您首先需要将要更改的 .cshtml 文件复制到插件中并进行修改。不要忘记将此文件设置为 Content 并将 Copy to Output Directory 属性设置为 Copy if Newer 或 Copy Always。

    之后,您还必须在插件中实现 IViewLocationExpander 接口。它应该看起来像这样。

    public class MyViewLocationExpander : IViewLocationExpander
    {
       public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
       {
          if(context.ViewName == "ViewToOverwrite")
          {
             viewLocations = new[] { "PathToMyCustomView" }.Concat(viewLocations);
          }
    
          return viewLocations;
        }
    
        public void PopulateValues(ViewLocationExpanderContext context)
        {
           return;
        }
    }
    

    最后一步是为插件注册您的自定义视图扩展器。 您可以通过在插件中实现 INopStartup 接口来做到这一点。它应该看起来像这样。

    public class MyStartup : INopStartup
    {
       public int Order => int.MaxValue;
    
       public void Configure(IApplicationBuilder application)
       {
       }
    
       public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
       {
          services.Configure<RazorViewEngineOptions>(options =>
          {
             options.ViewLocationExpanders.Add(new MyViewLocationExpander());
          });
       }
    }
    

    【讨论】:

      【解决方案2】:

      很简单,在你的插件中实现 ViewLocaionExpander。 这将覆盖您的视图,并将从插件的视图呈现

      【讨论】:

        【解决方案3】:

        您好,我使用了类似的解决方案来解决这个问题。 在你的 RouteProvider.cs

        public partial class RouteProvider : IRouteProvider
           {
            public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
                {
                       endpointRouteBuilder.MapControllerRoute("RedirectPdfPackagingSlip",
                            "Admin/yourController/yourAction",
                            new { controller = "Order", action = "PdfPackagingSlip" });
                }
            }
        

        然后回到你可以在控制器中使用的原始方法

          if (order.ShippingRateComputationMethodSystemName != "your shipping method SystemName")
                    return Redirect("~/Admin/Order/PdfPackagingSlip?shipmentId=" + ShipmentId);
        

        希望对你有帮助

        【讨论】:

          猜你喜欢
          • 2018-09-18
          • 2013-06-23
          • 1970-01-01
          • 1970-01-01
          • 2017-05-24
          • 2013-05-01
          • 2021-06-04
          • 2020-05-04
          • 2013-01-30
          相关资源
          最近更新 更多