Umbraco Controller. Routing. 为什么所有操作都显示404错误?

huangapple go评论59阅读模式
英文:

Umbraco Controller. Routing. Why I have 404 error for all actions?

问题

以下是您要翻译的代码部分:

我有这样的自定义控制器:

using System.Web.Mvc;
using Umbraco.Web.Mvc;
using HttpGetAttribute = System.Web.Mvc.HttpGetAttribute;
using RouteAttribute = System.Web.Mvc.RouteAttribute;
using RoutePrefixAttribute = System.Web.Mvc.RoutePrefixAttribute;

namespace MyProject.Host.Controllers
{
    [RoutePrefix("partnerClient")]
    public class PartnerClientController : UmbracoController
    {
        [HttpGet]
        [Route("firstClient")]
        public ActionResult FirstClient()
        {
            return View(@"~/Views/Partner/FirstPartnerClientView.cshtml");
        }
    }
}

我试图调用操作 {hostname}/partnerClient/firstClient
但我收到了一个错误:
页面未找到
没有与URL '/partnerClient/firstClient' 匹配的Umbraco文档。

但是,当我使用UmbracoApiController时,路由正常。

using Umbraco.Web.WebApi;
using HttpGetAttribute = System.Web.Http.HttpGetAttribute;
using RouteAttribute = System.Web.Http.RouteAttribute;
using RoutePrefixAttribute = System.Web.Http.RoutePrefixAttribute;

namespace MyProject.Host.Controllers
{
    [RoutePrefix("partnerClient")]
    public class PartnerClientController : UmbracoApiController
    {
        [HttpGet]
        [Route("firstClient")]
        public object FirstClient()
        {
            return "{test}";
        }
    }
}

对于此操作,我必须返回View,并且UmbracoApiController不允许这样做。
我应该如何配置UmbracoController的路由?或者我应该使用其他方法返回某个View?

英文:

I have custom controller like this:

using System.Web.Mvc;
using Umbraco.Web.Mvc;
using HttpGetAttribute = System.Web.Mvc.HttpGetAttribute;
using RouteAttribute = System.Web.Mvc.RouteAttribute;
using RoutePrefixAttribute = System.Web.Mvc.RoutePrefixAttribute;

namespace MyProject.Host.Controllers
{
    [RoutePrefix("partnerClient")]
    public class PartnerClientController : UmbracoController
    {
        [HttpGet]
        [Route("firstClient")]
        public ActionResult FirstClient()
        {
            return View(@"~/Views/Partner/FirstPartnerClientView.cshtml");
        }
    }
}

I am trying to call action {hostname}/partnerClient/firstClient
But I got an error:
Page not found
No umbraco document matches the URL '/partnerClient/firstClient'.

But when I use UmbracoApiController routing is ok.

using Umbraco.Web.WebApi;
using HttpGetAttribute = System.Web.Http.HttpGetAttribute;
using RouteAttribute = System.Web.Http.RouteAttribute;
using RoutePrefixAttribute = System.Web.Http.RoutePrefixAttribute;

namespace MyProject.Host.Controllers
{
    [RoutePrefix("partnerClient")]
    public class PartnerClientController : UmbracoApiController
    {
        [HttpGet]
        [Route("firstClient")]
        public object FirstClient()
        {
            return "{test}";
        }
    }
}

I have to return View for this action and UmbracoApiController doesn't allow it.
How I should configure routing for UmbracoController? Or maybe I should use some other way to return some View?

答案1

得分: 1

不确定您从哪里得到使用 "UmbracoController" 的想法,但您不应该使用它 :-/

请查看 https://our.umbraco.com/documentation/Reference/Routing/ - 看起来您应该使用 RenderMvcController,但请仔细查看文档以确保。

英文:

Not sure where you got the idea of using "UmbracoController" from - but you shouldn't :-/

Take a look at https://our.umbraco.com/documentation/Reference/Routing/ - it looks like you should use a RenderMvcController, but look through the docs to be sure.

huangapple
  • 本文由 发表于 2023年6月19日 18:10:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76505621.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定