I am attempting to develop a plugin our company needs for NOPCommerce.
I had some difficulty getting my controller and views to override the default ones and posted this SO question. From the kind assistance of the respondents I was able to get everything working. I went to work on another area of the code and when I came back it wasn't working completely.
I can get my controller to override and execute in all manner of configurations now that I understand the interactions with RouteProvider.cs.
My views however are not being hit...but they were as I had breakpoints and they were getting hit.
I know that MVC has a pattern / syntax expectation and that if you don't play within those bounds things don't work and I believe that is what is happening. My problem is I don't understand one of the rules of the game.
Here is the rundown as thoroughly as I can think of.
Plugin folder structure:
Directory Output:
C:\ ...\Presentation\Nop.Web\Plugins\Payments.StoreCredit\Core\Views\Order
My controller...which is getting hit...and route provider entry:
var OverrideRoute = routes.MapRoute("Plugin....OrderOverride", "Admin/Order/Edit/{id}",
new { controller = "Order", action = "Edit" },
new { id = @"\d+" },
new[] { "Company.Plugin.Payments.StoreCredit.Core.Controllers" }
);
routes.Remove(OverrideRoute); //remove route
routes.Insert(0, OverrideRoute); //add it back to the top
public ActionResult Edit(int id)
{
....again just to be clear controller is being hit...
return View(model);
}
CustomViewEngine:
protected override string GetPath(...parms)
{
...
//custom View locations to the top of the list to be given a higher precedence
newLocations.Insert(0, "~/Plugin/Payments.StoreCredit/Views/Core/{1}/{0}.cshtml");
....
}
Some things I've noticed but can't piece together
If I set a breakpoint on the CustomViewEngine it only ever gets hit when I actually browse the list of plugins such as:
//localhost:53764/Admin/Plugin/List
I've tried NUMEROUS variations of the CustomViewEngine newlocation.Insert but I always have just six paths that are searched. I believe my newlocations are inserted but they are not "applicable" to this context so they don't get searched? I say this because if I rename the edit.cshtml in the core admin project just to see the paths searched I get:
The path used by edit in the controller:
localhost:53764/Admin/Order/Edit/1006
returns:
Finally if I specify a path in the controller edit such as:
return View("~/Plugins/Payments.StoreCredit/Core/Views/Order/edit.cshtml", model);
My view is used..but then what's the point of all that fuss with the CustomViewEngine?
In other words I can kludge it together specifying paths in controllers but the CustomViewEngine is the more robust and professional way to go.