Sunday, 15 January 2012

jquery - Set cookie in Global.asax.cs and get it in the view of asp.net mvc c# -



jquery - Set cookie in Global.asax.cs and get it in the view of asp.net mvc c# -

i registered cookie in session start of global.asax.cs of asp.net mvc project. , want test variable of cookie in view.

global.asax.cs :

httpcookie instock = new httpcookie("instockv"); instock.value = "1"; response.cookies.add(instock);

in view, i'm using jquery :

<div id="test"></div> $("#test").text($.cookie("instockv"));

but result in div null.

anyone know issue please share.

thanks.

did add together plugin of jquery cookie? never less if don't have it, read cookie code it's pure javascript it's easy this

function getcookie(c_name) { var i, x, y, arrcookies = document.cookie.split(";"); (i = 0; < arrcookies.length; i++) { x = arrcookies[i].substr(0, arrcookies[i].indexof("=")); y = arrcookies[i].substr(arrcookies[i].indexof("=") + 1); x = x.replace(/^\s+|\s+$/g, ""); if (x == c_name) { homecoming unescape(y); } } }

update

tried in global.asax append this

httpcookie instock = new httpcookie("instockv"); instock.value = "1"; response.appendcookie(instock);

jquery asp.net-mvc cookies

No comments:

Post a Comment