在controller中给cookie赋值
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
HttpCookie cookie =newHttpCookie("pageInfo"); cookie["page_index"]= page_index.ToString(); cookie["page_count"]= page_count.ToString(); Response.AppendCookie(cookie);
另一个cookie赋值的例子
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
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
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
$("#ui_input_btn02").click(function (){ var page_data = getCookie("pageInfo").toString(); page_index =String(page_data).substr(11,1); var new_page =Number(page_index)-1; $.post("/Order/Page",{ data: new_page }, function (data){ var page_data = getCookie("pageInfo").toString(); page_index =String(page_data).substr(11,1); $("#page_now").text(page_index); $("#test").html(data);