英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论