简体   繁体   English

@Html.ActionLink 语言

[英]@Html.ActionLink For Language

How do I convert this to HTML action link如何将其转换为 HTML 操作链接

if (!string.IsNullOrEmpty(requestCulture.ToString()))
 {
     foreach (var item in cultureItems)
     {
         if (item.Value.Equals(requestCulture.ToString(), StringComparison.InvariantCultureIgnoreCase))
         {
             item.Selected = true;
             break;
         }
     }
 }

I'm able to generate the link by using我可以通过使用生成链接

if (!string.IsNullOrEmpty(requestCulture.ToString()))

{ foreach (var item in cultureItems) { if (item.Value.Equals(requestCulture.ToString(), StringComparison.InvariantCultureIgnoreCase)) { <a href=“@url”>@item.Name</a> } } }

But how do I generate the link for href that changes the language on the page.但是如何生成更改页面语言的 href 链接。 href=/fr-ca href=/fr-ca

<a>FR</a> <a>EN</a>

Because the parameter of ActionLink is wrong.因为ActionLink的参数不对。 It cannot generate correct action link.它无法生成正确的操作链接。 @Html.ActionLink can config five parameters. @Html.ActionLink可以配置五个参数。 The first and second parameter are required.第一个和第二个参数是必需的。

The first parameter is the text that will show in the view.第一个参数是将在视图中显示的文本。 The second parameter is action.第二个参数是动作。 The third parameter is routevalues.第三个参数是路由值。 Here is the example (Index.cshtml).这是示例 (Index.cshtml)。

@Html.ActionLink("text","get", new { key="item", value = "fr - ca" })

It is parsed by browser in this format.它由浏览器以这种格式解析。

<a href="/Home/get?key=item&amp;value=fr%20-%20ca">text</a>

In HomeController.在家庭控制器中。

    public IActionResult get(string key,string value)
    {
        return Json($"{key} {value}");
    }

Result.结果。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM