【问题标题】:404 Attribute Routing in Area404 区域内属性路由
【发布时间】:2017-06-22 16:49:56
【问题描述】:

当我尝试转到agency 区域的家庭控制器中的索引方法时,我收到一条 IIS 404 错误消息。如果我将route 属性更新为:[Route("{action}")] 它可以正常工作,但我想保留index 作为默认路由。

在我看来,我有这个:

@Html.ActionLink("Click here", "index", "home", new { area = "agency" }, new { @class = "btn btn-block btn-lg btn-primary" })

代理区域的 HomeController

namespace ProjectName.UI.Areas.Agency.Controllers
{
    [RouteArea("agency")]
    [RoutePrefix("home")]
    [Route("{action=index}")]
    public class HomeController : BaseController
    {

        public ActionResult Index()
        {
            return View();
        }
    }
}

路由配置:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapMvcAttributeRoutes();
    AreaRegistration.RegisterAllAreas();

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "home", action = "index", id = UrlParameter.Optional },
        namespaces: new[] { "ProjectName.UI.Controllers" }
    );
}

我还有一个管理区域,它看起来与代理区域完全相同,除了 RouteArea 是 admin 并且我没有任何问题。

欢迎提出任何建议。

【问题讨论】:

    标签: c# asp.net-mvc-5 attributerouting


    【解决方案1】:

    我发现问题是因为我的区域名为Agency,而在我的Views 文件夹中,我还有另一个名为Agency 的子文件夹。它没有路由到agency/home/index,而是试图在我的agency 文件夹中找到home 视图。

    【讨论】:

      猜你喜欢
      • 2014-01-12
      • 2013-12-29
      • 2014-12-22
      • 2020-10-07
      • 2013-12-26
      • 2015-09-09
      • 1970-01-01
      • 1970-01-01
      • 2015-06-12
      相关资源
      最近更新 更多