【发布时间】: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