小编Zas*_*shi的帖子

ASP.NET MVC5单击Html.ActionLink更改语言/文化

我的ASP.NET MVC5应用程序存在问题.我的应用程序可以设置浏览器中设置的lang/culture(现在只有英语和波兰语(默认)).我想通过点击Html.ActionLink让用户改变语言/文化.

我创建了一个类:

namespace Guestbook
{
    public static class Click
    {
        public static void SetCulture(string name)
        {
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(name);
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

我有我的观点:

@Html.ActionLink("PL", "", "Guests", routeValues: null, htmlAttributes: new { onclick = "SetCulture(\"pl\");" })
@Html.ActionLink("EN", "", "Guests", routeValues: null, htmlAttributes: new { onclick = "SetCulture(\"en\");" })
Run Code Online (Sandbox Code Playgroud)

当然,它不起作用.我还需要什么?JavaScript函数?

asp.net asp.net-mvc-5

4
推荐指数
1
解决办法
8805
查看次数

标签 统计

asp.net ×1

asp.net-mvc-5 ×1