在语言改变之后如何返回当前页面

时间:2015-08-06 11:15:26

标签: jquery asp.net asp.net-mvc twitter-bootstrap asp.net-mvc-4

ASP.NET MVC4应用程序允许选择语言:

public ActionResult SetCulture(string culture)
{
    // Validate input
    culture = CultureHelper.GetImplementedCulture(culture);
    // Save culture in a cookie
    HttpCookie cookie = Request.Cookies["_culture"];
    if (cookie != null)
        cookie.Value = culture;   // update cookie value
    else
    {
        cookie = new HttpCookie("_culture");
        cookie.Value = culture;
        cookie.Expires = DateTime.Now.AddYears(1);
    }
    Response.Cookies.Add(cookie);
    return RedirectToAction("Index");
}

点击链接后,调用控制器来更改语言:

*?

更改语言后,将显示主页。 如何强制单击链接的当前页面显示? RedirectToAction(“Index”)应该更改为返回当前页面。

html位于Site.Master中,可以从许多不同的页面调用。 MVC模板帐户控制器LogOn方法实现了这一点:它接收returnurl参数。如何将此参数传递给控制器​​?

使用Bootstrap 3,jquery,ASP.NET MVC4。

2 个答案:

答案 0 :(得分:0)

尝试:

public ActionResult SetCulture(string culture)
{
    // Validate input
    culture = CultureHelper.GetImplementedCulture(culture);
    // Save culture in a cookie
    HttpCookie cookie = Request.Cookies["_culture"];
    if (cookie != null)
        cookie.Value = culture;   // update cookie value
    else
    {
        cookie = new HttpCookie("_culture");
        cookie.Value = culture;
        cookie.Expires = DateTime.Now.AddYears(1);
    }
    Response.Cookies.Add(cookie);

    return Redirect(Request.Referrer.ToString());
}

答案 1 :(得分:0)

使用AJAX:

查看

    assertion failed: timeout (3 seconds) during expectMsg while waiting for success
    java.lang.AssertionError: assertion failed: timeout (3 seconds) during expectMsg while waiting for success

<强>控制器

<a href=# onclick="return Et();">et</a>

<script type="text/jscript">
    function Et()
    {
        //maybe do something
        $.get("/Home/Et?culture=et");                
    };
</script>