use*_*164 8 .net c# controller sitecore sitecore-mvc
我正在从这里学习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.
Run Code Online (Sandbox Code Playgroud)
我读过的所有帖子都与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>
Run Code Online (Sandbox Code Playgroud)
只有这条线给出了问题
@Html.Sitecore().Placeholder("content")
Run Code Online (Sandbox Code Playgroud)
如果我删除此行...它工作正常,浏览器上的页面显示日期和时间
的index.html
<p>Hello from Controller -todays Date is @DateTime.Now.ToString()</p>
Run Code Online (Sandbox Code Playgroud)
调节器
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果您已包含默认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 }
);
Run Code Online (Sandbox Code Playgroud)
请检查您的项目引用的System.Web.Mvc.dll版本。它可能晚于 Sitecore Website\Bin文件夹中的相同 dll 。请确保您的项目引用的 System.Web.Mvc.dll 版本与 Website\Bin 文件夹中的版本相同。
供参考。在ControllerRendering中指定控制器函数有两种方式:
| 归档时间: |
|
| 查看次数: |
34081 次 |
| 最近记录: |