我有一个包含三个区域(用户,区域,管理员)的MVC5项目。在“用户区域”中,我具有UserAreaRegistration.cs:
public class UsersAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Users";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Users_default",
"Users/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
new[] { "MyProject.Areas.Users.Controllers" }
);
}
}
在用户控制器中,我有DashBoardUsersController.cs:
namespace MyProject.Areas.Users.Controllers
{
[RouteArea("Users", AreaPrefix = "")]
[RoutePrefix("User")]
[Route("{action=index}")]
public class DashBoardUserController : Controller
{
[Route("index")]
[Route("dashboard")]
public async Task<ActionResult> Index()
{
...
return View(model);
//return View("~/Areas/Users/Views/DashBoardUser/Index.cshtml", model);
}
...
}
在添加[RouteArea("Users", AreaPrefix = "")]
之前,我曾使用
return View("~/Areas/Users/Views/DashBoardUser/Index.cshtml", model)
来调用http://localhost:5586/User/DashBoard
。
现在我只使用了return View(model)
,可以查看,但是ActionLink无法正常工作。
如果我写
@Html.ActionLink("Edit", "EditProfile", "User")
或
@Html.ActionLink("Edit", "EditProfile", "User", new {Area="Users" }, null)
我得到此链接:http://localhost:5586/Users/User/EditProfile
,而不是http://localhost:5586/User/EditProfile
怎么了?