【发布时间】:2015-08-06 11:15:26
【问题描述】:
ASP.NET MVC4 应用程序允许选择语言:
<div class="container-fluid">
<ul class="list-inline">
<li class="selected_language">
<a href="/admin/Home/SetCulture?culture=et" title="et">
et
</a>
</li>
<li>
<a href="/admin/Home/SetCulture?culture=en" title="en">
en
</a>
</li>
</ul>
点击链接后,调用控制器更改语言:
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。
【问题讨论】:
-
你可以传递额外的参数,比如 public ActionResult SetCulture(stringculture, string ActionName) return RedirectToAction(ActionName);
-
hmtl 代码是 Site.Master。如何在站点主控中查找 ActionName 参数值。页面中也可能有查询字符串。如何也传递查询字符串?
-
将操作名称存储在站点主控的隐藏字段中,使用 jquery/javascript 将隐藏字段值传递给查询字符串。
-
adamshakhabov 回答建议使用 ajax 和
location.reload()。哪个更好,您的解决方案还是 adamas 解决方案?或者也许有办法在没有 javascript 的情况下做到这一点,如何像第一个答案推荐的那样在控制器中获取整个 url?
标签: jquery asp.net asp.net-mvc twitter-bootstrap asp.net-mvc-4