Url to views for custom reports and admin plugins

Vote:
 

Hello!

I am working on a hobby project that will add an admin plugin and a couple of cms reports. I plan to package it as a nuget package for others to use. Currently I am stuck on how to set the url for the view files (Razor) and where to place them in the project.

I have been looking at a couple projects on GitHub and I currently have this (simplified) file structure:

ProjectRoot
  Controllers
    MyPluginController.cs
  modules
    _protected
      MyProjectName
        Views
          MyPlugin
            Index.cshtml

My controller looks like this:

    [GuiPlugIn(
        Area = PlugInArea.AdminConfigMenu,
        UrlFromModuleFolder = "Views/MyPlugin/Index",
        DisplayName = "This is my plugin"
    )]
    public class MyPluginController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    }

To test my code I have set up the AlloyMvc site as a second project in the solution and set Alloy to depend on my project. My plugin is detected and shows up in the admin interface but the view is not found. (error message reports searched physical path as {pathToSolution}\{theAlloyMvcProjectName}\EPiServer\CMS\Admin\MyPlugin\Index)

The EPiServer documentation on custom reports specifies a url in a hardcoded way and adds a route in the global.asax file but that is not an option.

I hope for a solution that makes it easy to test while coding and that also will work when package as a nuget and installed by someone else. What do I need to configure and where?

#207247
Sep 15, 2019 18:02
Vote:
 

Hi,

You should not use path to your view as "location" of the module. View is just a template that will be used by Razor ViewEngine to render the result. "Somebody" has to execute request - that's Mvc Controller. Instead - try to point to your controller:

[..., UrlFromModuleFolder = "MyPlugin", ...]

#207249
Sep 15, 2019 21:20
Vote:
 

I never tried making modules before. I tried changing the UrlFromModuleFolder as you showed but the same error message still appears but with a slightly changed path.

I have not specified any module location and only the assembly name in config files, and I do not find any location config settings in the projects I have been looking in for help either. I do not understand what you are saying I should change.

There are probably some more things I need to configure aswell. Currently to be able to run and debug my code at all I have added the bin file of the project's assembly as a dependency to the AlloyMvc project... (Its working, a Scheduled job that is a part of the module runs without any problems on Alloy)

I have uploaded my code to GitHub if anyone wants to take a look and come with suggestions on what may be wrong.

#207299
Sep 16, 2019 19:32
Vote:
 

look for PR..

#207378
Sep 17, 2019 21:01
Vote:
 

I have been trying some more things including the changes in valdis pull request.

After much struggle I have found a solution that requires me to build a nuget package and reinstall it everytime I want to test even the smallest changes in my dev environment. However, it is working!

#207489
Sep 22, 2019 12:31
Vote:
 

what are the changes?

#207495
Sep 23, 2019 0:34
Vote:
 

The biggest change was that I had to start building the project to a nuget and install it for the views to work, I had hoped to avoid the nuget step in my dev environment. Other things that I tried may also have been required, the code on GitHub is updated.

Here is my nuspec file and I build the package from inside the nuget-directory with the following command that gives me a package I can install in my test project:

nuget.exe pack ..\MoreCmsReports.csproj.nuspec

The routes section in module.config is not required, the UrlFromModuleFolder needs to match the controller name (excluding controller suffix).

#207500
Sep 23, 2019 8:18
Vote:
 

one trick might be to skip nuget step - to zip it up and the xcopy to sandbox project /modules/... folder. give it a try

#207501
Sep 23, 2019 9:28
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.