Asp.net mvc 4 根据第一个下拉列表中的选择填充资源文件中的第二个下拉列表
我有两个下拉列表来自一个资源文件。在第一个下拉列表中,我有四个选项,根据选择,我需要填充第二个下拉列表,它将根据选择来自唯一的资源文件。在资源文件中,我有一个包含4个字段(a、b、c、d)的主资源文件,然后我有4个不同的资源文件与每个选择一起使用。有人能告诉我如何在MVC4中填充它吗Asp.net mvc 4 根据第一个下拉列表中的选择填充资源文件中的第二个下拉列表,asp.net-mvc-4,html.dropdownlistfor,Asp.net Mvc 4,Html.dropdownlistfor,我有两个下拉列表来自一个资源文件。在第一个下拉列表中,我有四个选项,根据选择,我需要填充第二个下拉列表,它将根据选择来自唯一的资源文件。在资源文件中,我有一个包含4个字段(a、b、c、d)的主资源文件,然后我有4个不同的资源文件与每个选择一起使用。有人能告诉我如何在MVC4中填充它吗 @Html.DropDownListFor(m => m.country, new SelectList(frontend.Resources.Country.ResourceManager.GetResou
@Html.DropDownListFor(m => m.country, new SelectList(frontend.Resources.Country.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true), "Key", "Value").OrderBy(p => p.Value))
@Html.DropDownListFor(m => m.city, new SelectList(frontend.Resources.City1.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true), "Key", "Value").OrderBy(p => p.Value))
@Html.DropDownListFor(m => m.city, new SelectList(frontend.Resources.City2.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true), "Key", "Value").OrderBy(p => p.Value))
@Html.DropDownListFor(m => m.city, new SelectList(frontend.Resources.City3.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true), "Key", "Value").OrderBy(p => p.Value))
@Html.DropDownListFor(m => m.city, new SelectList(frontend.Resources.City.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true), "Key", "Value").OrderBy(p => p.Value))
使用ajax调用
$('#country').change(function() {
$.ajax({
url: "@(Url.Action("Action", "Controller"))",
type: "POST",
cache: false,
async: true,
data: { data: $('#country').val() },
success: function (result) {
//use the code from the link
}
});
});
您可以对每个下拉列表进行调用,并且可以调用任何控制器上的任何方法来获取数据。希望这能有所帮助。但我需要根据第一个下拉列表中的选择使用不同的资源文件,而不是像上面的链接那样过滤它。