_ViewImports.cshtml is ignored in Custom Plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 ano atrás
Views in custom Plugin cannot find 'NopHtml' helper nor the 'T' localizer.
_ViewImports.cshtml is present under Views folder as well the rest of the Views.

The plugin code is actually from the official course.

Note that injecting dependancies directly into the views works.

Version is 4.50.4
1 ano atrás
Do you have
@inject INopHtmlHelper NopHtml
in your _ViewImports.cshtml file
1 ano atrás
Yes. The _ViewImports file looks like this:

@inherits Nop.Web.Framework.Mvc.Razor.NopRazorPage<TModel>
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Nop.Web.Framework
@addTagHelper *, Nop.Plugin.Misc.SupportRequests

@using Microsoft.AspNetCore.Mvc.ViewFeatures
@using Nop.Core
@using Nop.Web.Framework.UI
@using Nop.Web.Framework.Extensions
@using System.Text.Encodings.Web

@inject INopHtmlHelper NopHtml
1 ano atrás
Are you getting errors when the code runs, or just in Visual Studio's syntax validation?
1 ano atrás
The plugin is built and appears in the Nop.Web.Plugins folder but there are several problems:

1. At the admin panel the Plugin keeps its "ready to install" state after installation and app restart.
I mean there are no 'Configure' and 'Edit' buttons as well as 'Install' and 'Delete' Buttons remain instead of 'UnInstall'.

2. Localization does not function for the plugin views. Localization keys appear as text instead of the values.

3. No views or components of the plugin appear in the Admin section.
1 ano atrás
Are you running the 'published' version, or are you running in Visual Studio?

RE: "Plugin keeps its "ready to install"
Then it seems like it did not install properly.
Check \App_Data\plugins.json file.  Is your plugin still in the "PluginNamesToInstall" section (near bottom of file)

Check your .csproj file.  Be sure that output for build is under \Presentation\ .  Example:
<OutputPath>..\..\Presentation\Nop.Web\Plugins\Shipping.FixedByWeightByTotal</OutputPath>

RE:  "Localization does not function for the plugin views. "
The plugin he installation inserts localized string resources into DB table.  If install is no completing, then that won't happen.
1 ano atrás
I run the app in VS.
The OutputPath is correct as you show.
And the plugin also appears in the plugins.json under "PluginNamesToInstall".
1 ano atrás
Check the System > Log for errors
1 ano atrás
Problem solved!

After looking at the logs, it turns out it was a migration problem. After making the appropriate corrections to the database everything works as it should.

(Editor still complains for the _ViewImports though)
Thank you for your time and advice!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.