我一直在閱讀Wooncherk,Twisted Whisperer和Alex Wolf的一些很好的帖子。他們的文章分別是(Wooncherk),(Twisted Whisperer)和(Alex Wolf)已經非常翔實,但可惜我只是不如SO社區的其他人聰明,不能完全湊齊我失蹤的東西。非常接近但不能完全覆蓋核心視圖nopcommerce
我重寫了管理區域中的核心視圖...特別是順序編輯視圖。我看到的行爲是它不是命中我的插件中的控制器,但它DOES顯示我的自定義視圖。問題是自定義視圖在Admin項目中,這真讓我困惑。我如何擁有一個獨立的插件,但必須將我的自定義視圖安裝到核心管理區域?
我想,也許不正確,會發生什麼是我的控制器會因爲我的更高定義的優先級搜索路徑時被首先命中。
所以按照這裏的指示是我的代碼。
CustomViewEngine:
private readonly string[] _emptyLocations = null;
public CustomViewEngine()
{
PartialViewLocationFormats = new[]
{
"~/Administration/MyExtension/Views/{1}/{0}.cshtml",
"~/Administration/MyExtension/Views/Shared/{0}.cshtml"
};
ViewLocationFormats = new[]
{
"~/Administration/MyExtension/Views/{1}/{0}.cshtml",
"~/Administration/MyExtension/Views/Shared/{0}.cshtml"
};
}
protected override string GetPath(ControllerContext controllerContext, string[] locations, string[] areaLocations, string locationsPropertyName, string name, string controllerName, string theme, string cacheKeyPrefix, bool useCache, out string[] searchedLocations)
{
searchedLocations = _emptyLocations;
if (string.IsNullOrEmpty(name))
{
return string.Empty;
}
string areaName = GetAreaName(controllerContext.RouteData);
//little hack to get nop's admin area to be in /Administration/ instead of /Nop/Admin/ or Areas/Admin/
if (!string.IsNullOrEmpty(areaName) && areaName.Equals("admin", StringComparison.InvariantCultureIgnoreCase))
{
var newLocations = areaLocations.ToList();
newLocations.Insert(0, "~/Administration/Views/{1}/{0}.cshtml");
newLocations.Insert(0, "~/Administration/Views/Shared/{0}.cshtml");
//Insert your custom View locations to the top of the list to be given a higher precedence
newLocations.Insert(0, "~/Administration/MyExtension/Views/{1}/{0}.cshtml");
newLocations.Insert(0, "~/Administration/MyExtension/Views/Shared/{0}.cshtml");
areaLocations = newLocations.ToArray();
}
bool flag = !string.IsNullOrEmpty(areaName);
List<ViewLocation> viewLocations = GetViewLocations(locations, flag ? areaLocations : null);
if (viewLocations.Count == 0)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Properties cannot be null or empty.", new object[] { locationsPropertyName }));
}
bool flag2 = IsSpecificPath(name);
string key = CreateCacheKey(cacheKeyPrefix, name, flag2 ? string.Empty : controllerName, areaName, theme);
if (useCache)
{
var cached = ViewLocationCache.GetViewLocation(controllerContext.HttpContext, key);
if (cached != null)
{
return cached;
}
}
if (!flag2)
{
return GetPathFromGeneralName(controllerContext, viewLocations, name, controllerName, areaName, theme, key, ref searchedLocations);
}
return GetPathFromSpecificName(controllerContext, name, key, ref searchedLocations);
}
路由供應看評論 試圖覆蓋核心URL〜/管理/訂單/編輯/ 1
public void RegisterRoutes(RouteCollection routes)
{
ViewEngines.Engines.Insert(0, new CustomViewEngine());
//the articles above did NOT mention adding a path but it seemed like I needed to in order for my override path to be included???
routes.MapRoute("Plugin...OrderDetailsOverride", "Order/Edit/{id}",
new { controller = "MyOrder", action = "Edit" },
new { id = @"\d+" },
new[] { "MyPlugin.Controllers" }
);
}
public int Priority
{
get
{
return 1;
}
}
我得到一個404錯誤,仔細的閱讀扭曲語他(我假設他)說:
例如,如果你是overrding Nop.Admin /瀏覽/分類/ Tree.cshtml,將您的自定義樹.cshtml在Nop.Admin/CustomExtension /瀏覽/分類/ Tree.cshtml
好吧,如果我解釋,從字面上我將在CORE ADMIN項目做到這一點:
我明顯這樣做,它的工作... sorta。
因此,在總結我的問題/問題是:
在插件我的訂單覆蓋控制器是打不到....(不使用ActionFilters感興趣,因爲他們不給我什麼,我需要......我不認爲)。
我的插件中的視圖沒有命中,但添加到管理項目中的視圖命中?
與2有些相關。如果兩個是正確的,那麼這個可行的插件解決方案如何?對於產品推送,更新等,我可能不得不觸及NopCommerce核心項目....那麼爲什麼還要插入一個插件呢?
現在NOP傢伙以及SO社區都比我更聰明,所以我相信我只是不明白。
你是否看到我的文章的意見部分?我的讀者有幾個更新,可以解決您的問題? :) – wooncherk 2014-10-08 08:39:26