IComponents 视图的 Nop Commerce 自定义视图引擎在 nopcommerce 4.0 中不起作用
Nop Commerce Custom View Engine for IComponents View Does'nt work in nopcommerce 4.0
我在 NopCommerce v4.0 的自定义插件中有以下代码
我正在尝试覆盖 nopcommerce 中 IComponent 的默认 ordertotal 页面,并尝试使用给定代码从我的插件中覆盖
ViewLocationExpander.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
}
}
它的调用是在 ExpandViewLocations.cs 文件中进行的,路径也没有问题,但是它在 Views/shared/component/OrderTotals/Default.cshtml
中重定向了 nopcommerce 的默认页面
我尝试了很多不同的方法,但没有得到任何解决方案
如果有人有想法请回复
谢谢
伊利亚斯·帕特尔
我遇到了同样的问题,在 nop 4.0 中它们采用默认视图路径,您必须像这样声明
viewLocations = new string[] { $"/Plugins/Demo/Views/{{0}}.cshtml"
}.Concat(viewLocations);
很有帮助
我在 NopCommerce v4.0 的自定义插件中有以下代码
我正在尝试覆盖 nopcommerce 中 IComponent 的默认 ordertotal 页面,并尝试使用给定代码从我的插件中覆盖
ViewLocationExpander.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
}
}
它的调用是在 ExpandViewLocations.cs 文件中进行的,路径也没有问题,但是它在 Views/shared/component/OrderTotals/Default.cshtml
中重定向了 nopcommerce 的默认页面我尝试了很多不同的方法,但没有得到任何解决方案 如果有人有想法请回复
谢谢 伊利亚斯·帕特尔
我遇到了同样的问题,在 nop 4.0 中它们采用默认视图路径,您必须像这样声明
viewLocations = new string[] { $"/Plugins/Demo/Views/{{0}}.cshtml"
}.Concat(viewLocations);
很有帮助