我有一些代碼使用min_row/max_row獲取我的數據。我想通過我的菜單中的頁碼以及分頁鏈接。ASP.Net MVC3外部數據分頁
我的主菜單有這樣的代碼:
@Html.ActionLink("MyDocuments", "", "Home/MyDocuments/1")
我的分頁鏈接是這樣的:
(他們將建立在從ViewBag發出了記錄總數的蒼蠅,不與部分完成尚):
<ul>
<li><a href="#">Prev</a></li>
<li class="active"><a href="/Home/MyDocuments/1">1</a></li>
<li><a href="/Home/MyDocuments/2">2</a></li>
<li><a href="/Home/MyDocuments/3">3</a></li>
<li><a href="/Home/MyDocuments/4">4</a></li>
<li><a href="#">Next</a></li>
</ul>
這裏是我的控制器操作:
public ActionResult MyDocuments(int Page)
{
string min = (Page-1*50).ToString();
string max = (50/Page).ToString();
// mps is a webservice reference
Archive docs = mps.GetArchiveArray(LogonTicket, PID, "SortColumn", max, min, "ASC");
ViewBag.docs = docs;
return View();
}
現在,當我點擊主菜單中的項目,我得到這個錯誤:
The parameters dictionary contains a null entry for parameter 'Page'
of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult
MyDocuments(Int32)' in 'MVC3MySite.Controllers.HomeController'.
這是我在Global.asax.cs中MapRoutes:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
如何規避這個錯誤?
以下答案是正確的,或者更改操作參數爲int的ID。 btw:string min =((Page-1)* 50).ToString() – MiBu
將參數更改爲id導致:「參數字典包含非空的參數'id'條目...' – MB34