我整天都很困惑,我有一个区域路由,它看起来像这样。
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "admin";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRouteLowercase(null, "Account/{action}",
new {controller = "Account"},
new {action = @"LogOff|LogOn|Create|Update|Delete|List"},
new[] {"WebUI.Areas.Admin.Controllers"});
context.MapRouteLowercase( //this works
"AdminUpdateCategoryView",
"admin/{controller}/{action}/{cid}",
new {area = "admin", controller = "Main", action = "UpdateCategory", cid = ""},
new {cid = @"\d+"},
new[] {"WebUI.Areas.Admin.Controllers"}
);
context.MapRouteLowercase(//this not works
"AdminCategoryListView",
"admin/Main/{action}/{page}",
new { action = "Category", page = "1" },
new {page = @"\d+"},
new[] {"WebUI.Areas.Admin.Controllers"}
);
context.MapRouteLowercase(
"Admin_Default", // Route name
"admin/{controller}/{action}/{id}", // URL with parameters
new {controller = "Category", action = "Index", id = UrlParameter.Optional} // Parameter defaults
);
}
}
我已经写了哪些有效,哪些无效,但是如果在它们之间改变一个不起作用,有效,另一个有效,不工作?
例子:
first case-> /admin/main/updatecategory/1 --> works /admin/main/category/1 --> not works result: /admin/main/category/1?page=1 second case-> /admin/main/category/1 --> works /admin/main/updatecategory/1 --> not works result: /admin/main/updatecategory/1?cid=1
这是我的控制器操作:
public ActionResult Category(int? page)
{
int pageIndex = page.HasValue ? page.Value : 1;
return View("Category", CategoryViewModelFactory(pageIndex));
}
public ActionResult CreateCategory()
{
return View();
}
public ActionResult UpdateCategory(int cid)
{
return View();
}
public ActionResult DeleteCategory(int? cid)
{
return View();
}
这是什么问题以及如何解决?
我很困惑,ASP.MVC3 中的路由是电子逻辑的。
帮助?!