我在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的默认页面。
我已经尝试了许多不同的方法,但是如果有人有任何想法都没有得到任何解决方案,请回复
谢谢Ilyas Patel
我遇到同样的问题,在nop 4.0中,它们采用默认视图路径,您必须像这样声明
viewLocations = new string[] { $"/Plugins/Demo/Views/{{0}}.cshtml"
}.Concat(viewLocations);
它会有所帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句