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();
}
}
}
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 }
);
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:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With