HTML
=================
@{int Lid = Convert.ToInt32(Request.Cookies["LID"].Value);}
<a class="@(Lid == 1 ? "comnBtn activelid" : "comnBtn")" id="enbtn" href="/Language/ChangeLanguage?Lang=en">English</a>
<a class="@(Lid == 2 ? "comnBtn activelid" : "comnBtn")" id="arbtn" href="/Language/ChangeLanguage?Lang=ar">Arabic</a>
controller:
====================
=================
@{int Lid = Convert.ToInt32(Request.Cookies["LID"].Value);}
<a class="@(Lid == 1 ? "comnBtn activelid" : "comnBtn")" id="enbtn" href="/Language/ChangeLanguage?Lang=en">English</a>
<a class="@(Lid == 2 ? "comnBtn activelid" : "comnBtn")" id="arbtn" href="/Language/ChangeLanguage?Lang=ar">Arabic</a>
controller:
====================
public ActionResult ChangeLanguage(string Lang)
{
if (Lang != null)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Lang);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(Lang);
var cookie = new HttpCookie("Language");
var cookieLID = new HttpCookie("LID");
if (Lang == "en")
cookieLID.Value = "1";
else
cookieLID.Value = "2";
cookie.Value = Lang;
Response.Cookies.Add(cookie);
Response.Cookies.Add(cookieLID);
}
return Redirect(Request.UrlReferrer.ToString());
}
Use of Cookies
======================
[HttpGet]
public ActionResult faq()
{
_FAQ obj = new _FAQ();
int Lid = Convert.ToInt32(Request.Cookies["LID"].Value);
obj = (new CMSdata()).faqByLID("GetbyLid", Lid);
return View(obj);
}
No comments:
Post a Comment