Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The controller for path '/' was 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 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();
        }

    }
}
like image 762
user3767164 Avatar asked Sep 25 '14 05:09

user3767164


4 Answers

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 }
 );
like image 80
PizzaTheHut Avatar answered Oct 19 '22 03:10

PizzaTheHut


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.
like image 42
Gerzson Avatar answered Oct 19 '22 04:10

Gerzson


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.

like image 1
Carlos Rodriguez Avatar answered Oct 19 '22 04:10

Carlos Rodriguez


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.

like image 1
Somayeh_Hosseini Avatar answered Oct 19 '22 03:10

Somayeh_Hosseini