Set cookie value before view loaded in MVC?

Posted by James123 on Stack Overflow See other posts from Stack Overflow or by James123
Published on 2014-06-02T15:23:05Z Indexed on 2014/06/02 15:25 UTC
Read the original article Hit count: 171

I need to set a cookie value before my view called. otherwise I have to refresh the page to get cookie value in the view. The problem here is the value of cookie will get in controller.

[HttpGet]
[Route("Abstract/{meetingCode}")]
[AllowAnonymous]
public ActionResult Index(string meetingCode)
{
 var meetingAbstract = new MeetingAbstract();
 meetingAbstract.Meeting = _abstractContext.GetMeetingWithMeetingCode(meetingCode);
 if (meetingAbstract.Meeting != null)
 {
   var cookie = new HttpCookie("_culture");
   cookie.Value = meetingAbstract.Meeting.language.language_locale_code;//"en-US"; 
   cookie.Expires = DateTime.Now.AddDays(365);
   cookie.Path = "/";
   this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
...

Any other way without refresh the page again to set cookie value?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about asp.net-mvc-4