c# - 路径 '/' 的 Controller 未找到或未在 Sitecore 中实现 IController

标签 c# .net controller sitecore sitecore-mvc

我正在从 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/

相关文章:

c# - 如何在WebAPI应用程序的Swagger UI中添加方法描述

c# - Silverlight 的鸭子类型(duck typing)库?

c# - 我应该为包含 10 个或更少项目的集合使用字典,还是有更好的选择?

c# - 写入使用 AsciiEncoding.GetBytes 和 Convert.FromBase64String 解码的字节时 FileStream.Write 中的性能问题

java - Mockito 异常 - when() 需要一个参数,该参数必须是模拟上的方法调用

c# - 进行 SSL 连接时需要主机名验证

c# - 发送邮件失败,邮箱不可用

c# - 将非常大的整数压缩成尽可能小的字符串

asp.net-mvc-3 - asp.net mvc3 创建一个将始终执行的 Controller 方法

Java FX 更改前一阶段场景中的标签文本