Razor view error

Vote:
 

Created an Add-On. A block type out of that Add-On just working well. A page type out of the same Add-On gives the error below. The view exists. It was working once. Don't know what I've changed. Any idea?

 

Server Error in '/' Application.


The view 'index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/BasePage/index.aspx
~/Views/BasePage/index.ascx
~/Views/Shared/index.aspx
~/Views/Shared/index.ascx
~/Views/BasePage/index.cshtml
~/Views/BasePage/index.vbhtml
~/Views/Shared/index.cshtml
~/Views/Shared/index.vbhtml

#64254
Dec 14, 2012 14:21
Vote:
 

Does the View exist in one of the places listed in the error?

What is the inherant path set to?

#64262
Dec 14, 2012 14:59
Vote:
 

Yes, the view exists. The strcutrue looks like:

C:\EPISERVER\SITES\SITEDIR\MODULES\MYADDON
├───bin
│   └───net40
│       ├───de
│       ├───es
│       └───fr
├───Content
└───Views
    ├───BaseBlock
    └───BasePage

The view is located in the BasePage directory. Was also located there when it was working. I also tried specifiying the path by myself and got the same error message with the correct full patch to the view. So it definitly exists at the right location!

return View(Paths.ToResource(this.GetType(),"Views/index.cshtml"), model);

I don't have a web.config in the MYADDON directory and also not in the Views directory. So everything should be configured out of the box. Or should I have somewhere a web.config file? If yes, why it was working once without a web.config file?

 

 

 

#64263
Edited, Dec 14, 2012 15:50
Vote:
 

In addition, if I right click in visual studio the controllers Index method and select "Go to View" the right view opens.

#64266
Dec 14, 2012 16:14
Vote:
 

What does your control look like? . Do you have view for the index action or are you redirecting the index action to your action? 

From the code you posted you seem to be returning BasePage.cshtml but MVC is looking for /Vies/BasePage/index.cshtml

#64267
Dec 14, 2012 16:15
Vote:
 

    public class BasePageController : PageControllerBase<BasePage>
    {

        private static readonly ILog logger =
                LogManager.GetLogger(typeof(BasePageController));

        [ContentOutputCache]
        public ActionResult Index(BasePage currentPage)
        {
            if (logger.IsDebugEnabled)
                logger.Debug("Index - START");
            
            var model = new BasePageModel();
            if (currentPage != null)
            {
                model.Heading = currentPage.Heading;
                model.Body = currentPage.MainBody;
                model.MyBlock = currentPage.MyBlock;

                var editingHints = ViewData.GetEditHints<BasePageModel, BasePage>();
                editingHints.AddConnection(x => x.Body, x => x.MainBody);
            }
            else
            {
                if (logger.IsDebugEnabled)
                    logger.Debug("Index - NULL currentPage");
            }

            if (logger.IsDebugEnabled)
                logger.Debug("Index - DONE");
            return View(model);
        }

    }

#64268
Dec 14, 2012 16:16
Vote:
 

The view 'index' or its master was not found or no view engine supports the searched locations. Maybe the problem is related to masterpage?

Do you have the same problem when using this way?

return View(Paths.ToResource(this.GetType(),"Views/BasePage.cshtml"), model);

    

Sometimes you need to add config file in your add-on vierws folder to let razor engine know about your model. I blogged about similar thing here, please see "MVC block rendering" section. It was about EPiServer 7 Preview, but most of it should be accurate.

#64269
Dec 14, 2012 16:32
Vote:
 

If I read your file structure correctly, the BasePage and BaseBlock are folders, not views. 

If Dmytro's suggestion doesn't work, you should try:
return View(Paths.ToResource(this.GetType(),"Views/BasePage/index.cshtml"), model);

#64270
Edited, Dec 14, 2012 16:33
Vote:
 

If I read your file structure correctly, the BasePage and BaseBlock are folders, not views. 

If Dmytro's suggestion doesn't work, you should try:
return View(Paths.ToResource(this.GetType(),"Views/BasePage/index.cshtml"), model);

#64271
Dec 14, 2012 16:40
Vote:
 

Exactly, it should be the partial path to the view in your add-on folder.

#64273
Dec 14, 2012 16:45
Vote:
 

Hello all. Problem was related to the inherited class. Because I don't have a web.config, I need to inherit the view from System.Web.Mvc.WebViewPage. Here is the statement:

@inherits System.Web.Mvc.WebViewPage<Namespace.Models.BasePageModel>

Now I have the problem that my model namespace could not be found.

Compiler Error Message: CS0246: The type or namespace name could not be found (are you missing a using directive or an assembly reference?)

 

So I've added a small web.config to add my dll:
<configuration>
  <system.web>
    <compilation>
      <assemblies>
        <add assembly="Namespace.CMS.BaseLayout" />
      </assemblies>
    </compilation>
  </system.web>
</configuration>

May now I get:

The controller for path '/admin/internal/UI/CMS/en/BBB,,16_21/' was not found or does not implement IController.

 

So not working without a web.config and not working with a web.config.

#64279
Edited, Dec 14, 2012 17:53
Vote:
 

Hi, Konrad,

Any updates regarding your issue? It seems that i'm receiving the same error.

#64303
Dec 17, 2012 14:20
Vote:
 

Regarding error "The controller for path '/admin/internal/UI/CMS/en/BBB,,16_21/' was not found or does not implement IController.":

It looks like this is a bug, you can find more information here.

You can try following workaround: add your assembly in system.web/compilation/assemblies section in web.config manually:

<configuration>
… 
  <system.web>
    <compilation … >
      <assemblies>
         …
        <add assembly="Your.Assembly.Name" />
      </assemblies>
    </compilation>
  </system.web>
</configuration>

    

#65237
Jan 23, 2013 15:04
Vote:
 

...and now the fix is available in EPiServer 7 Patch 1 (bug #91052).

#65420
Jan 29, 2013 15:58
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.