在controller中给cookie赋值
HttpCookie cookie =newHttpCookie("pageInfo"); cookie["page_index"]= page_index.ToString(); cookie["page_count"]= page_count.ToString(); Response.AppendCookie(cookie);
另一个cookie赋值的例子
HttpCookie cookie = Request.Cookies["OldCookieName"];
cookie.Values["CompanyID"] = Convert.ToString(CompanyId);
Response.SetCookie(cookie); //SetCookie is used for update the cookies.
Response.Cookie.Add(cookie); //This is used for Add cookies.
前端用getCookie来操作cookie
$("#ui_input_btn02").click(function (){ var page_data = getCookie("pageInfo").toString(); page_index =String(page_data).substr(,); var new_page =Number(page_index)-; $.post("/Order/Page",{ data: new_page }, function (data){ var page_data = getCookie("pageInfo").toString(); page_index =String(page_data).substr(,); $("#page_now").text(page_index); $("#test").html(data);