【问题标题】:Cannot find the Umbraco route definition in the route values在路由值中找不到 Umbraco 路由定义
【发布时间】:2016-06-08 08:38:32
【问题描述】:

我正在尝试做一些相当基本的事情,但它似乎不起作用。 我有一个剃须刀页面,我在 NewsSurfaceController 中调用了一个动作“索引”。

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    Layout = "Master.cshtml";
}
<div class="row">
    <h1 class="col-xs-12 col-sm-4">@CurrentPage.Name</h1>
    <div class="col-xs-12 col-sm-2 col-sm-offset-4 ">
        @Html.ActionLink("Archief", "Archive", "NewsSurface", null, new { @class = "content-link-button-reverse" })
    </div>
</div>



@Html.Action("Index", "NewsSurface")

我的新闻控制器:

public class NewsSurfaceController : SurfaceController
{
    private int itemsPerpage= 4;

    public ActionResult Index()
    {
        return PartialView("newslist", new NewsRepo(CurrentPage).items.Take(itemsPerpage));
    }

    public ActionResult Archive()
    {
       return PartialView("newslist", new NewsRepo(CurrentPage).archivedItems.Take(itemsPerpage));
    }

}

这将返回一个仅遍历项目的局部视图。

@inherits Umbraco.Web.Mvc.UmbracoViewPage<MyProject.models.NewsItemViewModel>


        @foreach (MyProject.models.NewsItem item in Model)
        {
            //displays the properties
        }

当我转到该页面时,它会正确显示项目,但是当我单击操作链接时会引发错误。

在路由值中找不到 Umbraco 路由定义,请求必须在 Umbraco 请求的上下文中进行

当我调试时,问题似乎出在“CurrentPage”对象上。

在 Umbraco.Web.Mvc.SurfaceController.get_CurrentPage() 在 C:\Users\thomas\Documents\Visual Studio 2015\Projects\MyProject\Controllers\NewsSurfaceController.cs:line 25 中的 MyProject.Controllers.NewsSurfaceController.Archive() 在 lambda_method(闭包,ControllerBase,对象 []) 在 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase 控制器,Object[] 参数) 在 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext 控制器上下文,IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 参数) 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod() 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult,ActionInvocation innerInvokeState) 在 System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() 在 System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult,对象标记) 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d() 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.c__DisplayClass46.b__3f()

我做错了什么? 谁能指出我正确的方向。

亲切的问候!

---------编辑--------

好的显然这是 Umbraco 中的一个错误。 Issue on the umbraco forum

【问题讨论】:

    标签: c# razor umbraco


    【解决方案1】:

    您的控制器是否继承自 SurfaceController?否则,将不会为您注册路线。

    【讨论】:

    • 感谢您的回复。很抱歉造成混乱,我应该将完整的控制器代码放在我的帖子中。它继承自 SurfaceController。
    猜你喜欢
    • 2018-03-12
    • 2016-02-10
    • 1970-01-01
    • 1970-01-01
    • 2015-03-19
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    相关资源
    最近更新 更多