asp.net mvc 3 - mvc3 cookie value not setting in ViewData page -
i have textbox , submit button people put in there enter 5 number pin , safed inside cookie 4 months not working im getting nothing out of it.. wrong.. first time trying cookies
read view
public actionresult index() { //read cookie , send view model var mycookie = request.cookies["mypreference"]; viewdata["prefvalue"] = mycookie.value; return view(); }
httppost
[httppost] public actionresult index(formcollection ss) { // create cookie httpcookie preference = new httpcookie("mypreference"); preference.value = ss["preffer"]; preference.expires = datetime.now.adddays(120d); response.cookies.add(preference); return view(); }
the view
@using (html.beginform("seotips", "home", formmethod.post)) { @html.textbox("preffer") <input type="submit" value="submit" /> } @viewdata["prefvalue"]
you have try
public actionresult index() { httpcookie coo = new httpcookie("name"); coo["country"] = "india"; viewdata["prefvalue"] = coo["country"]; return view(); }
Comments
Post a Comment