Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Episerver addon development with Razor view engine - Can't resolve view

Vote:
 

Hi guys,

I'm in the process of developing an Episerver addon. My addon is strucuted like an MVC application and is heavily inspired by the skeleton project at https://github.com/mariajemaria/AddOn.Initial. I am using Razor views as they are supposedly supported since version 10.10.0 (I'm specifically at 11.1.0). However, I can't seem to get the addon to resolve my razor views properly. I'm getting the infamous exception: 

The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/MyModule/Index.cshtml
... 
...
... etc.

This is my controller:

    [Authorize]
    [GuiPlugIn(
        RequiredAccess = EPiServer.Security.AccessLevel.Administer,
        Area = PlugInArea.AdminMenu,
        Url = "/my-module/index",
        DisplayName = "My Module")]
    public class MyModuleController : Controller
    {
        public ActionResult Index()
        {
            return View(new MyModuleViewModel { Text = "World" });
        }
    }

My view is located at ~/Views/MyModule/Index.cshtml and looks like this:

@model MyEpiserverModule.Models.MyModuleViewModel

@{
    Layout = null;
}





    title


Hello @Model.Text!

My module.config:



  
    
  

Moreover, my module is setup as a Nuget package and this is a snippet of my .nuspec file:



  
   ...
    EPiServerModulePackage
    
      
      
    
  
  
    
    
    
    
  

When you install the nuget package to an Episerver project, the zip file is correctly placed in ~/modules/_protected/MyEpiserverModule/MyEpiserverModule.zip and the web.config.install.xdt makes sure the section of the project's Web.config looks like this:


	
	
		...
		
	

The zip file seems to contain all necessary files in the correct structure.

Can anyone see what I am missing that's preventing my views from resolving properly? My project can be downloaded at https://www.dropbox.com/s/5bhemb3k0rttbtr/MyEpiserverModule.zip?dl=0. There is a Nuget package located at the project's root. This can be installed to an Alloy project to test the module. It shows up correctly in the "Tools" section of the Episerver admin interface. But when I click on the link to open it, the exception is thrown complaining about the missing view.

Any feedback is greatly appreciated. Thanks for your time.

#188301
Feb 19, 2018 12:17
Vote:
 

This post may help:

https://getadigital.com/blog/enable-razor-views-in-episerver-modules-with-geta.epi.shellrazorsupport-package/

#188325
Feb 20, 2018 0:20
Vote:
 

Hi David, 

Thanks for your response.

I have looked into the Geta plugin, and while it seems to be a great plugin I would really prefer to utilize the official support for Razor views in my particular case. The release notes does indicate that it is now supported, and the author of the Geta plugin goes a long way in recommending its users to move on to the officially supported approach. 

#188340
Feb 20, 2018 12:48
Vote:
 

Hi, I just wrote about how to create a plugin using razor views: https://swapcode.wordpress.com/2018/03/16/how-to-create-episerver-admin-plugin-using-razor-view-engine-and-mvc/

The difference in my implementation is that there is no custom initilization modules needed and no custom routes. Maybe my posting helps you if you still have this issue.

#189355
Mar 15, 2018 22:23
Vote:
 

Thanks for sharing your blog! 

#189356
Mar 15, 2018 22:48
Vote:
 

There was a bug in CMS Ui which prevents the shell from resolving the paths of Razor views. It will be fixed in the upcoming 11.4.1 release.

#189357
Mar 15, 2018 23:10
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.