Controller for path '/' not found or does not implement IController in Sitecore

I am learning controller rendering in Sitecore from here .

I created one simple controller (HelloWorld) and a related view (Index.schtml). He matched it (with the name PageContent) in the rendering section of the Sitecore Explorer ... and adds the rendering element to the "Home item in the content section of the Sitecore browser" section. But when I look at it, it gives an error.

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

All the posts I read relate to Asp.Net MVC .. but I have a problem related to Sitecore MVC

Sample.html (Content of the page in the rendering section of the Sitecore Explorer)

 @using Sitecore.Mvc <html> <body> @Html.Sitecore().Placeholder("content") <p>Today date is @DateTime.Now.ToShortDateString()</p> </body> </html> 

Only this line poses a problem

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

If I delete this line ... This works fine, and the page in the browser shows the 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(); } } } 
+8
source share
7 answers

This can happen if you enable MVC routes by default, as they override the implementation of the Sitecore native controller.

Make sure you delete the following lines from RouteConfig.cs / Global.cs (depending on the version of MVC);

  routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); 
+8
source

Please check the version of System.Web.Mvc.dll that your project is referencing. This may be later than the same DLL in the Sitecore \ Bin Website . Make sure that your project references the same version of System.Web.Mvc.dll as in the \ Bin site folder.

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

  • Only the name of the controller. (Please omit the controller suffix in this case)
  • Fully qualified name. For example, "Project.Controllers.HelloWorldController, Project". In this case, do not omit the suffix "Controller".
+3
source

Something else I would like to add is the following. I got the same answer in Sitecore, and then I noticed the need for the following type of elements.

Layout → Controllers → [Type of link to control]

I created each controller element for each controller and it seems to cover the gap between the controller rendering elements in the content tree under Renderings and the actual controller in the code. The contents of this controller element provide the namespace and dll where the controller code is stored, and the action that the controller action points to.

Hope this helps. Since the use of these elements, the error has disappeared. I am using Sitecore 8.0, by the way, in my example.

+1
source

In addition to Carlos' answer, I also had to add my model to the CMS, under the "Models:

enter image description here

0
source

This may be due to the installation of MVC in different places on different servers, but changing the "Application Pool Identification" for the application in IIS to "LocalSystem" fixed the problem for me. I redesigned the application pool for the application and restarted the web service for the application after the change.

0
source

--- Working Solution ---

This error occurs due to different versions of your Sitecore.Web.Mvc.Dll in the solution help folder (Project name-> References-> Sitecore.Web. Mvc-> right-click and check the properties) and the version of Sitecore.Web.Mvc .Dll in Web.Config in the view folder.

To resolve this error, you must ensure that the version of Sitecore.Web.Mvc.Dll is the same in both folders.

Thanx.

0
source

The problem in my project was that I used asp.net mvc 5.2.4, but when installing by default from sitecore, 5.2.3 was used, and the wrong version was used in the web.config folder from my views folder, and the error did not appear. what is version mismatch! After lowering my solution to 5.2.3, it worked.

I found this in another thread. I installed Sitecore 9.1 using scripts and my web.config in the Views folder really refers to 5.2.3, so I got tired of lowering System.Web.Mvc to 5.2.3 as suggested, and copied / pasted the .dll into my instance of sc910.sc, but that did not solve the problem. Still looking for a solution.

UPDATE

I was trained on Sitecore 9.1, but ran into the same problem. It turns out that I am getting an error because I (Visual Studio) have not published my entire project. After creating a new controller, you need to rebuild your project, otherwise the .dll will not be updated and an 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: before publishing your project, I strongly recommend that you expand your links, select all the links, open the properties menu and set the Copy Local property to False . If you do not, your .dll will cause problems, if your wwwroot project and wwwroot project do not contain exactly the same version of the .dll, this causes pain in the application script. In addition, I highly recommend setting the action assembly properties in both main web.config and one of which is located in the Views folder to None, if you do not, you will end up with compilation errors.

0
source

Source: https://habr.com/ru/post/975815/


All Articles