c# – 未找到路径’/’的控制器或未在Sitecore中实现IController

前端之家收集整理的这篇文章主要介绍了c# – 未找到路径’/’的控制器或未在Sitecore中实现IController前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在从 Here学习Sitecore中的Controller渲染.

我创建了一个简单的控制器(HelloWorld)和相关视图(Index.schtml).在Sitecore Explorer的渲染部分中映射它(使用Name PageContent)…并在Sitecore Explorer的内容部分中的Home Item中添加渲染项目.但是当我浏览它时,它会给出错误.

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")

如果我删除此行…它工作正常,浏览器上的页面显示日期和时间

的index.html

<p>Hello from Controller -todays Date is @DateTime.Now.ToString()</p>

调节器

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自己的控制器实现.

确保您已从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 }
 );
原文链接:https://www.f2er.com/csharp/101136.html

猜你在找的C#相关文章