Nop Commerce Custom View Engine for IComponents View 在 nopCommerce 4.0 中不起作用



我在nopcommerce v4.0

的自定义插件中具有以下代码

我正在尝试覆盖nopcommerce中iComponent的默认订单的页面,并尝试使用给定代码

从我的插件中超平面

ViewLocation Expander.cs

public class BundledDiscountsViewEngine : IViewLocationExpander  
{
    public void PopulateValues(ViewLocationExpanderContext context)
    {
        //nothing to do here.
    }
    public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
    {
        if (context.AreaName == null && context.ViewName == "Components/OrderTotals/Default")
        {
            viewLocations = new string[] { $"/Plugins/Demo/Views/Components/OrderTotals/{{0}}.cshtml"
            }.Concat(viewLocations);
        }
        return viewLocations;
    }
}

nopstartup.cs

public class NopStartup : INopStartup
{
    public void ConfigureServices(IServiceCollection services, IConfigurationRoot configuration)
    {
        services.Configure<RazorViewEngineOptions>(options =>
        {
            options.ViewLocationExpanders.Add(new ViewLocationExpander());
        });
    }
    public void Configure(IApplicationBuilder application)
    {
    }
    public int Order
    {
        get { return 1001; } //add after nopcommerce is done
    }
}

它的调用是在ExplentViewLocations.cs文件中出现的,路径也可以,但它重定向nopCommerce的默认页面,在views/shared/component/component/component/ordertotals/default.cshtml

中重定向。

我尝试了许多不同的事情,但没有得到任何解决方案如果有人有主意,请回复

谢谢Ilyas Patel

i面临同一问题,在NOP 4.0中,他们需要像这样声明这样的默认视图路径

  viewLocations = new string[] { $"/Plugins/Demo/Views/{{0}}.cshtml"
                }.Concat(viewLocations);

它可以帮助

最新更新