那麼,在教程中,他們並沒有真正「保存在內存」之間的請求。在每個請求中,該值都傳遞給action方法,然後將其傳遞給視圖,並在該方法中用於創建分頁和排序鏈接。
以前,尋呼,而不是單獨地將每個參數時,我只是有讀取查詢字符串和使用每個提供參數建立的鏈路的方法:
NameValueCollection queryString = helper.ViewContext.HttpContext.Request.QueryString;
foreach (string key in queryString)
{
if (key != null)
{
if (!newValues.ContainsKey(key))
{
if (!string.IsNullOrEmpty(queryString[key]))
{
newValues[key] = queryString[key];
}
}
}
}
然後,創建鏈接,我使用:
string link;
if (!string.IsNullOrEmpty(routeName))
{
link = helper.RouteLink(text, routeName, newValues).ToString();
}
else
{
actionName = actionName ?? values["action"].ToString();
controllerName = controllerName ?? values["controller"].ToString();
link = helper.ActionLink(text, actionName, controllerName, newValues, null).ToString();
}
return string.Concat(" ", link);