asp.net mvc - MVC Controller Action cookie.add not persisting after jQuery .load() -
in view have jquery script fires on dropdown list change. calls controller action performs various logic , either updates or adds cookie. i'm finding cookie not getting created , suspect it's because jquery reloading page.
jquery:
<script type="text/javascript"> $(function () { $('#selectedlanguage').on('change', function () { var civilization = $(this).val(); $('#test').load("/account/testpartial/" + culture, function () { location.reload(true); }); }); }); </script>
code called controller action:
if (request.cookies["usersettings"] != null && request.cookies["usersettings"]["culture"] != null) { var existingcookie = request.cookies["usersettings"]; existingcookie.values["culture"] = selectedlanguage; existingcookie.expires = datetime.now.adddays(50 * 365); response.cookies.set(existingcookie); } else { httpcookie cookie = new httpcookie("usersettings"); cookie.values["culture"] = selectedlanguage; cookie.expires = datetime.now.addmonths(1); response.cookies.add(cookie); }
is accurate response.cookies.add() succeed cookie not written due location.reload(true);
on return?
if so, there way around this? i'm needing cookie exist 1 time reload finished.
if isn't problem, see why cookie wouldn't exist after reload?
jquery asp.net-mvc cookies
No comments:
Post a Comment