Asp.net mvc ASP.NET MVC多语言功能无法按预期工作

Asp.net mvc ASP.NET MVC多语言功能无法按预期工作,asp.net-mvc,asp.net-mvc-3,Asp.net Mvc,Asp.net Mvc 3,我让应用程序使用单选按钮运行,例如 @using (Html.BeginForm("SetCulture", "Home")) { <input type="radio" name="culture" id="en-us" value="en-us" class="culture" /> English <input type="radio" name="culture" id="tr" value="tr" class="culture" /> Türk } 家庭控制

我让应用程序使用单选按钮运行,例如

@using (Html.BeginForm("SetCulture", "Home"))
{
<input type="radio" name="culture" id="en-us" value="en-us" class="culture" /> English
<input type="radio" name="culture" id="tr" value="tr" class="culture" /> Türk
}
家庭控制器代码:

$(".culture").click(function () {
     $(this).parents("form").submit(); // post form
});
public ActionResult SetCulture(string culture){
    // action code here
}
我看不出为什么这些图像不起作用,但出于某种原因它发生了。有什么想法吗

非常感谢您

在第一个代码块中(使用
),您的表单将只为
区域性
发回一个值(所选单选按钮的值)

在第二个代码块(使用
)中,表单将回发两个输入的值,因此表单数据为
culture=en-US&culture=tr

DefaultModelBinder
将绑定第一个值并忽略第二个值,因此无论单击哪个图像,POST方法中的
culture
值都将始终为“en-US”

一个选项是禁用其他输入(例如,禁用的输入不会回发值)

$(".culture").click(function () {
    $(this).siblings().prop('disabled', true); // disable the other input
    $(this).parents("form").submit(); // post form
});
另一种处理方法是使用

$('.culture')。单击(函数(){
$('#culture').val($(this.data('culture'));//更新隐藏的输入
$('form').submit();
})

虽然这很有道理,但修复不起作用,那么您问题中的代码是您真实视图中的确切代码吗(我显示的代码确实起作用)?是的,它也适用于文本(收音机旁边)但我需要单击标志图像。是否有其他控件可能满足要求?您可能遇到的一个问题是,
type=“image”
将根据浏览器进行提交(即您两次提交)您可以添加<代码>返回false <代码>作为脚本中的最后一行代码,以防止默认提交。您可以始终考虑将单选按钮设置为图像。
$(".culture").click(function () {
    $(this).siblings().prop('disabled', true); // disable the other input
    $(this).parents("form").submit(); // post form
});
<input type="hidden" name="culture" id="culture"/>
<img src="~/Content/Images/en.png" data-culture="en-US" class="culture" />
<img src="~/Content/Images/tr.png" data-culture="tr" class="culture" />

$('.culture').click(function () {
    $('#culture').val($(this).data('culture')); // update the hidden input
    $('form').submit();
})