The controller for path '/' was not found or does not implement IController in Sitecore
Asked Answered
L

11

8

I am learning Controller rendering in Sitecore from Here .

I created One simple controller(HelloWorld) and Related View(Index.schtml) . Mapped it(with Name PageContent) in rendering section of Sitecore Explorer... and Add Rendering Item in Home Item in Content Section of Sitecore Explorer.. But When I Browse it, it gives the Error .

The controller for path '/' was not found or does not implement IController. 

All the post I have Read are related to Asp .Net MVC ..but I have issue related to Sitecore MVC

Sample.html (Page Content in Sitecore Explorer Rendering Section)

@using Sitecore.Mvc

<html>
<body>
    @Html.Sitecore().Placeholder("content")

    <p>Today's date is @DateTime.Now.ToShortDateString()</p>
</body>

</html>

Only this Line is giving Problem

@Html.Sitecore().Placeholder("content")

If I remove this line ...It Works fine and page on Browser show date and time

Index.html

<p>Hello from Controller -todays Date is @DateTime.Now.ToString()</p>

Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVC.Controllers
{
    public class HelloWorldController : Controller
    {
        //
        // GET: /HellowWorld/

        public ActionResult Index()
        {
            return View();
        }

    }
}
Lordinwaiting answered 25/9, 2014 at 5:59 Comment(0)
B
9

This can occur if you have included the default MVC routes, as they override Sitecore's own controller implementation.

Ensure that you have removed the following lines from RouteConfig.cs/Global.cs (depending on MVC version);

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

 routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
 );
Brighton answered 25/9, 2014 at 16:14 Comment(0)
R
6

Please check the version of System.Web.Mvc.dll referenced by your project. It maybe later than the same dll in Sitecore Website\Bin folder. Please ensure that your project references the same version of System.Web.Mvc.dll as the one in the Website\Bin folder.

FYI. There are two ways to specify the controller function in the ControllerRendering:

  • By just the controller name. (Please omit the "Controller" suffix in this case)
  • By the fully qualified name. For example "Project.Controllers.HelloWorldController, Project". In this case do not omit the "Controller" suffix.
Recognizee answered 12/2, 2015 at 15:6 Comment(3)
What happened here was some security update from microsoft upped the MVC 3's version to 3.0.0.1. The website was bound to 3.0.0.1 but compiled libraries I was using were still bound to 3.0.0.0 and they were unable to understand my controllers.Bogle
"By just the controller name." - gets me every time!Lightface
@gerzson damn, the downvote was completely unvoluntary, clicked by mistake after some tabs shuffling, sorry...Danish
G
1

Something else I would like to add is the following. I was getting the same answer in Sitecore and then I noticed the need for the following item type.

Layout -> Controllers -> [Controller Item Reference Type]

I created each controller item for each controller and that seem to bridge the gap between the controller rendering items in the content tree under Renderings and the actual controller in code. The content of this controller item provides the namespace and dll where the code of the controller is stored and the action which the controller action points to.

I hope this helps. Since using these items, the error has gone away. I am using Sitecore 8.0 by the way in my example.

Grevera answered 29/7, 2015 at 16:53 Comment(0)
D
1

I ran into this error once again. In this more recent case it was because my rendering item's controller field was misspelled. You can use a fully qualified name in the controller field to avoid namespace conflicts. In my case the correct fully qualified name was as follows:

enter image description here

So the first portion is the full namespace path including the controller name followed by a coma then by the project name:

enter image description here

enter image description here

Discontent answered 20/8, 2020 at 15:35 Comment(0)
T
1

I faced with the same error in my program. Actually I had a class to render Partial View To string, but I made a terrible mistake and put function parameters incorrectly.

PartialToStringClass.RenderPartialView("ManageEmails", "RecoveryPassword", user);

The first parameter is my contrller name and the second one is my Partial View name. But I changed their place by mistak.

Tokenism answered 13/4, 2021 at 7:22 Comment(0)
O
0

In addition to Carlos' answer, i also had to add my model in CMS, under Models:

enter image description here

Oxime answered 29/9, 2017 at 11:19 Comment(0)
S
0

This may be related to the MVC being installed in different places on different servers but changing the 'Application Pool Identity' for the application in IIS to 'LocalSystem' fixed the issue for me. I Recycled the App Pool for the app & Restarted the web service for the app after the change.

Seriatim answered 24/10, 2018 at 19:58 Comment(0)
C
0

---Working Solution---

This error will come because of the different versions of your Sitecore.Web.Mvc.Dll in solution reference folder(Project name->References->Sitecore.Web.Mvc->right click and check properties) and the version of Sitecore.Web.Mvc.Dll in Web.Config in views Folder.

For solving this error you have to make sure that the version of Sitecore.Web.Mvc.Dll is same in both folders.

Thanx.

Cochabamba answered 15/11, 2018 at 10:37 Comment(0)
D
0

The Problem in my project was that I was using asp.net mvc 5.2.4 but the default installation from sitecore was using 5.2.3 and in the web.config from my views folder there was the wrong version used and the error was not showing that there is a version missmatch! After downgrading my solution to 5.2.3 it was working.

I found this on another thread. I installed Sitecore 9.1 using the scripts and my web.config within the Views folder does indeed reference 5.2.3 so I tired downgrading my System.Web.Mvc down to 5.2.3 as this suggests and copy/pasting the .dll over to my sc910.sc instance but it didn't fix the issue. Still looking for a solution.

UPDATE

I went through Sitecore 9.1 training, while doing so I encountered the same issue. Turns out I was getting the error because I had not (Visual Studio) published my entire project. After creating a new controller it is required that you rebuild your project otherwise the .dll is not updated and the error will occur. It is recommended that you create a publish profile and then use the publish web button to do this.

Another important thing to point out is, before publishing your project I highly recommend you expand your References, select all of the references, open the properties menu, then set the Copy Local property to False. If you do not do this your .dlls will cause issues if both your wwwroot project and out of wwwroot project do not contain the exact same .dll version, this is causes a pain in the butt scenario. Also, I highly recommend setting the Build Action properties within both your main web.config and the one located within your Views folder to a value of None, if you don't do this you will end up with compilation errors.

Discontent answered 17/1, 2019 at 21:50 Comment(0)
D
0

I just ran into this issue as well. I resolved it by

  1. Updating the views/web.config to include the a compiler node to point to the DotNetCompilerPlatform type.
  2. Updating the project reference to ensure that the same version of Microsoft.CodeDom.Providers.DotNetCompilerPlatform was output to the bin folder.
      <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs"                type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
         </compiler>
        </compilers>
     </system.codedom>
Disgust answered 9/1, 2020 at 16:48 Comment(0)
I
0

Do make sure that you include the Controller in your website project's proj file... I accidentally left the proj file in my local Excluded Changes so it was working locally but broke with this error when the code reached the test environment. After thinking this was a Sitecore issue for a couple hours I realized that it was much simpler than that for me.

Insane answered 7/5, 2021 at 22:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.