我愿意覆盖" _RentalInfo.cshtml"和" _AddToCart.cshtml"我的插件中的页面。为此,我创建了自定义视图引擎,并将文件路径提供为" PartialViewLocationFormats,ViewLocationFormats"。 // CustomViewEngine类
public class CustomViewEngine : ThemeableRazorViewEngine
{
public CustomViewEngine()
{
PartialViewLocationFormats = new[] { "~/Plugins/Misc.Rental/Views/Product/{0}.cshtml" };
ViewLocationFormats = new[] { "~/Plugins/Misc.Rental/Views/Product/{0}.cshtml" };
}
}
然后,我在Plugin中创建了RouteProvider.cs文件并添加了我的" CustomViewEngine"在视图引擎列表中。我还将路由提供商的优先级设置为最高。
//RouteProvider
public partial class RouteProvider : IRouteProvider
{
#region Fields
public int Priority
{
get
{
return int.MaxValue;
}
}
#endregion
#region Methods
public void RegisterRoutes(RouteCollection routes)
{
ViewEngines.Engines.Add(new CustomViewEngine());
}
#endregion
}
最后,根据我的" CustomViewEngine"中提到的路径,我创建了" _RentalInfo.cshtml"和" _AddToCart.cshtml"页面下方"视图"我的插件中的文件夹。
但是,那么默认的NopCommerce默认局部视图也只是显示。 任何人都可以查看我的代码并让我知道,我执行了错误或遗漏的内容以覆盖部分视图。
答案 0 :(得分:0)
我在我的插件中使用以下代码
public PluginRazorViewEngine()
{
PartialViewLocationFormats = new[]
{
"~/Plugins/My.Plugin/Views/{1}/{0}.cshtml",
"~/Plugins/My.Plugin/Views/Shared/{0}.cshtml",
};
ViewLocationFormats = new[]
{
"~/Plugins/My.Plugin/Views/{1}/{0}.cshtml",
"~/Plugins/My.Plugin/Views/Shared/{0}.cshtml",
};
AreaPartialViewLocationFormats = new[]
{
"~/Plugins/My.Plugin/Views/{1}/{0}.cshtml",
"~/Plugins/My.Plugin/Views/Shared/{0}.cshtml",
};
AreaViewLocationFormats = new[]
{
"~/Plugins/My.Plugin/Views/{1}/{0}.cshtml",
"~/Plugins/My.Plugin/Views/Shared/{0}.cshtml",
};
}
// {0} in format gets filled with view name.
// {1} in format gets filled with controller name.
我不确定哪一个会解决你的问题。
只需用 Misc.Rental 替换 My.Plugin 就可以了。