如何在编辑页面MVC中重新绑定drowdownlist? [英] How can I rebind the drowdownlist in edit page MVC?
问题描述
我正在研究MVC 5,我有Viewmodel Class'PartnersVM'。
I am working on MVC 5, there I have Viewmodel Class ' PartnersVM '.
public class PartnersVM
{
public List<CountryVM> listCountry { get; set; }
public PartnerVM listPartnerVM { get; set; }
}
public class CountryVM
{
public int idCountry { get; set; }
public string countries_name { get; set; }
}
public class PartnerVM
{
public string ServiceDistricts { get; set; }
public string ServiceStates { get; set; }
}
我尝试过:
这是ActionResult Get方法。
What I have tried:
And this is ActionResult Get method.
[HttpGet]
public ActionResult PremiumUserRegistration()
{
PartnersVM objcountrymodel = new PartnersVM();
objcountrymodel.listCountry = new List<CountryVM>();
objcountrymodel.listCountry = objPartnerBIL.ShowCountries().Select(item => new CountryVM
{
idCountry = item.idCountry,
countries_name = item.countries_name
}).ToList();
return View("PremiumUserRegistration", objcountrymodel);
}
调用此actionresult后现在绑定国家/地区列表。还有下拉的onchage调用jscript函数进行绑定下面的下拉菜单。
查看:
After calling this actionresult now binding list of countries. And the dropdown onchage calling a jscript function for bind below dropdowns also.
View:
@Html.DropDownListFor(model => model.listCountry, new SelectList(Model.listCountry, "idCountry", "countries_name"), "Select", new { @class = "form-control ", @id = "ddlcountries", @onchange = "return getuserstate.search(this.value)" })
@Html.DropDownListFor(model => model.listPartnerVM.ServiceStates, Enumerable.Empty<SelectListItem>(), "Select Country", new { @id = "ddlstate", @class = "form-control ", @onchange = "return getdistricts.search(this.value)" })
@Html.DropDownListFor(model => model.listPartnerVM.ServiceDistricts, Enumerable.Empty<SelectListItem>(), "Select State", new { @id = "ddlDistrict", @class = "form-control " })
这里得到那些drowdown的值,同时去编辑Get action方法如下图所示。
[ ^ ]
现在,一切正常。但问题是,我在移动编辑页面时无法重新绑定那些drowdown列表。这里添加/编辑页面是一个。如何重新绑定下拉列表?
请帮助我...
Here getting those drowdown's value while going to edit Get action method as show below image.
[^]
Now, all are working fine. But the problem is, I can not rebind those drowdown list while moving on edit page. Here Add/Edit page is one. How can I rebind the dropdownlist?
Please help me...
推荐答案
此Google搜索: mvc刷新下拉列表ajax - Google搜索 [ ^ ]
发现以下内容: c# - 使用AJAX MVC 4填充DropDownList - Stack Overflow [ ^ ]
This Google Search: mvc refresh dropdown list ajax - Google Search[^]
Found the following: c# - Populate DropDownList using AJAX MVC 4 - Stack Overflow[^]
这篇关于如何在编辑页面MVC中重新绑定drowdownlist?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!