2017-06-22 77 views
0

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

在我看来,我有这样的:

@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(); 
     } 
    } 
} 

RouteConfig:

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,我没有任何问题。

任何建议都会受到欢迎。

回答

0

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