我需要帮助。我正在尝试创建一个带有法语和英语文本的下拉框,而不是我现在认为的两个链接。我在 MVC 中工作,我需要一个下拉框,它应该根据用户的语言选择自动提交(没有提交按钮的额外步骤),但只是根据选择发布。可能有一些方法可以使用选择标签和选项标签以及一些 javascript,但我只是不确定如何。有谁知道如何做到这一点?
这是我的控制器
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
namespace MultiLanguage.Controllers
{
public class LanguageController : Controller
{
// GET: Language
public ActionResult Index()
{
return View();
}
public ActionResult Change(String LanguageAbbrevation)
{
if(LanguageAbbrevation !=null)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(LanguageAbbrevation);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(LanguageAbbrevation);
}
HttpCookie cookie = new HttpCookie("Language");
cookie.Value = LanguageAbbrevation;
Response.Cookies.Add(cookie);
return View("Index");
}
}
}
这是我的看法
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<ul>
<li>@Html.ActionLink("English","Change","Language",new {LanguageAbbrevation = "en"}, null)</li>
<li>@Html.ActionLink("French", "Change", "Language", new { LanguageAbbrevation = "fr" }, null)</li>
<li>@DateTime.Now.ToString()</li>
</ul>