【问题标题】:Asp.net MVC - Area Attribute Routing is not workingAsp.net MVC - 区域属性路由不起作用
【发布时间】:2016-08-19 09:15:54
【问题描述】:

我有如下代码

[RouteArea("Client")] 
public Class LoginController : Controller {
    [Route("register")]
    public ActionResult SignUp() {
        return View();
    }
}

不幸的是,属性路由在这些区域中不起作用:/,如果我将删除“注册”路由以进行注册,它将仅适用于客户端/注册,但使用路由“注册”它不起作用。

我添加了[RouteArea()],尝试使用[RoutePrefix],但没有任何东西可以正常工作“路线区域”刚刚启用以将其与视图一起使用(在此之前,Razor 无法找到视图)。

我做错了什么?

【问题讨论】:

    标签: c# asp.net-mvc-4 asp.net-mvc-routing


    【解决方案1】:

    好的,我找到了解决方案。

    1 从您的区域中删除区域注册类

    2 使用此约定:

    [RouteArea("Client")]
    [RoutePrefix("login")]
    [Route("{action}")]
    public class LoginController : Controller
    {
    
        [Route("")]
        // GET: Client/Login
        public ActionResult Index()
        {
            return View();
        }
    
        [Route("register")]
        // GET: client/login/register
        public ActionResult SignUp()
        {
            return View();
        }
    }
    

    现在你可以使用任何你想要的路线,任何前缀:)

    【讨论】:

      猜你喜欢
      • 2015-06-12
      • 2013-12-26
      • 2018-09-01
      • 2017-01-16
      • 2013-06-01
      • 2019-03-05
      • 2010-12-09
      • 2018-05-31
      • 1970-01-01
      相关资源
      最近更新 更多