问题:我希望我的路线是这样的
/admin/main/category/1 -> 1 == ?page=1 我不想看到 page=1
我的控制器
public class MainController : BaseController
{
private const int PageSize = 5; //pager view size
[Inject]
public ICategoryRepository CategoryRepository { get; set; }
public ActionResult Index()
{
return View();
}
public ActionResult Category(int page)
{
//int pageIndex = page.HasValue ? page.Value : 1;
int pageIndex = page != 0 ? page : 1;
return View("Category", CategoryViewModelFactory(pageIndex));
}
/*
*Helper: private instance/static methods
======================================================================*/
private CategoryViewModel CategoryViewModelFactory(int pageIndex) //generate viewmodel category result on pager request
{
return new CategoryViewModel
{
Categories = CategoryRepository.GetActiveCategoriesListDescending().ToPagedList(pageIndex, PageSize)
};
}
}
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "admin";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRouteLowercase(
"AdminCategoryListView",
"admin/{controller}/{action}/{page}",
new { controller = "Category", action = "Category", page = "1" },
new { id = @"\d+" },
new[] { "WebUI.Areas.Admin.Controllers" }
);
}
}
My Exception:
参数字典包含“WebUI.Areas.Admin.Controllers.MainController”中方法“System.Web.Mvc.ActionResult Category(Int32)”的不可为空类型“System.Int32”的参数“页面”的空条目。可选参数必须是引用类型、可空类型或声明为可选参数。参数名称:参数
谢谢大家。