我正在从 Here 学习 Sitecore 中的 Controller 渲染.
我创建了一个简单的 Controller (HelloWorld)和相关 View (Index.schtml)。在 Sitecore Explorer 的渲染部分映射它(使用名称 PageContent)...并在 Sitecore Explorer 的内容部分的主项目中添加渲染项目。但是当我浏览它时,它给出了错误。
The controller for path '/' was not found or does not implement IController.
我读过的所有帖子都与 Asp .Net MVC 相关......但我有与 Sitecore MVC 相关的问题
Sample.html(Sitecore Explorer 呈现部分中的页面内容)
@using Sitecore.Mvc
<html>
<body>
@Html.Sitecore().Placeholder("content")
<p>Today's date is @DateTime.Now.ToShortDateString()</p>
</body>
</html>
只有这条线有问题
@Html.Sitecore().Placeholder("content")
如果我删除这一行......它工作正常并且浏览器上的页面显示日期和时间
索引.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();
}
}
}
最佳答案
如果您包含默认的 MVC 路由,就会发生这种情况,因为它们会覆盖 Sitecore 自己的 Controller 实现。
确保您已从 RouteConfig.cs/Global.cs 中删除以下行(取决于 MVC 版本);
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
关于c# - 路径 '/' 的 Controller 未找到或未在 Sitecore 中实现 IController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26031639/