Hi folks,
Wondering if anyone has bumped into an issue that I am experiencing. I have a nop 4.2 based widget plugin.
This plugin has several business functions going on so I have multiple components setup to inject into the base platform for various widget zones. Everything is good there.
Now, I have a scenario where I am creating my own Component (unrelated to a any widgetzone). Basically, I have a View in my plugin that has the following in it;
<div class="side-2">
@await Component.InvokeAsync("CategoryTreeNavigation", new { currentCategoryId = currentCategoryId })
</div>
This line finds the CategoryTreeNavigation correctly in my plugin which looks as follows;
...
[ViewComponent(Name = "CategoryTreeNavigation")]
public class CategoryTreeNavigationViewComponent : NopViewComponent
{
public IViewComponentResult Invoke(int currentCategoryId)
{
var model = new CategoryHelperModel();
model.CategoryId = currentCategoryId;
//return View("~/Plugins/Widgets.MyPlugin/Views/Shared/Components/CategoryTreeNavigation/Default.cshtml", model);
return View(model);
}
}
...
Now according to a ton of googling, by default, any component view is going to look for "Default.cshtml" in the Views/Shared/Components/.../Default.chstml path. This is why it seems ootb, Component Views for Nop.Web are stored where they are.
I tried overriding the location of the view (the line commented out) in above and it just never seems to be able to find the view.
Error
The view 'Components/CategoryTreeNavigation/~/Plugins/Widgets.MyPlugin/Views/Shared/Components/CategoryTreeNavigation/Default.cshtml' was not found. The following locations were searched:
...
In a controller, by default, it looks for the same name as the function or Index.cshtml and the View() function is overloaded to be able to just give a direct path to the view.
In Components, it is "supposed" to work this way (with the exception it looks for default.cshtml) but I can't seem to get the right structure in my plugin (Works fine for the nop.web project). It keeps prefixing with Components/CategoryTreeNavigation.
Anyone have any luck with creating their own components and invoking them in a plugin?
thx