我在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的默认页面
我尝试过很多不同的东西,但没有得到任何解决方案 如有任何想法请回复
谢谢 伊利亚斯帕特尔
答案 0 :(得分:2)
我面临同样的问题,在nop 4.0中,他们采用默认视图路径,你必须像这样声明
viewLocations = new string[] { $"/Plugins/Demo/Views/{{0}}.cshtml"
}.Concat(viewLocations);
它可以提供帮助