更新时间:2022-06-01 22:58:33
试试这些:
http://www.binaryintellect.net/articles/b58fde6b-415e-454d-985b -d5dc4ad2fca8.aspx [ ^ ]
http://www.c-sharpcorner.com/UploadFile/4d9083/creating-simple-cascading-dropdownlist-in-mvc-4-using-razor/ 一> [ ^ ]
ASP.NET MVC级联下拉列表 [ ^ ]
http://www.c-sharpcorner.com/UploadFile/raj1979/dropdown-cascading-in-mvc4-using-entity-framework/ [ ^ ]
祝你好运
try these:
http://www.binaryintellect.net/articles/b58fde6b-415e-454d-985b-d5dc4ad2fca8.aspx[^]
http://www.c-sharpcorner.com/UploadFile/4d9083/creating-simple-cascading-dropdownlist-in-mvc-4-using-razor/[^]
An ASP.NET MVC Cascading Dropdown List[^]
http://www.c-sharpcorner.com/UploadFile/raj1979/dropdown-cascading-in-mvc4-using-entity-framework/[^]
Good luck
在你的控制器下你应该试试这个,我认为它会对你有所帮助。
公共ActionResult各省()
{
//这里我正在创建一个通用列表,我正在添加一个项目
List< selectlistitem> prov = new List< selectlistitem>();
prov .Add(new SelectListItem {Text =Select Province,Value =0});
prov。添加(新的SelectListItem {Text =Northern Cape,Value =1});
prov .Add(new SelectListItem {Text =Eastern Cape,Value =2});
prov .Add(new SelectListItem {Text =Free State,Value =3});
prov .Add(new SelectListItem {Text =Western Cape ,Value =4});
prov .Add(new SelectListItem {Text =Limpopo,Value =5});
prov .Add (new SelectListItem {Text =North West,Value = 6});
prov .Add(new SelectListItem {Text =KwaZulu-Natal,Value =7});
prov .Add(new SelectListItem {Text =Mpumalanga,Value =8});
prov .Add(new SelectListItem {Text =Gauteng,Value = 9});
//在ViewData中存储省份它会将它们传递给视图
ViewData [province] =道具;
retu查看();
}
//现在您可以通过右键单击ActionResults方法省来添加视图,然后您必须选择添加视图
@using(Html.BeginForm())
{
@ Html.DropDownList(省,ViewData [省 ]作为列表< selectlistitem>)
}
Under your controller you should try this, I think it will help you.
public ActionResult Provinces()
{
//Here i'm creating a generic list and I am adding an item to it
List<selectlistitem> prov = new List<selectlistitem>();
prov .Add(new SelectListItem { Text = "Select Province", Value = "0" });
prov .Add(new SelectListItem { Text = "Northern Cape", Value = "1" });
prov .Add(new SelectListItem { Text = "Eastern Cape", Value = "2" });
prov .Add(new SelectListItem { Text = "Free State", Value = "3" });
prov .Add(new SelectListItem { Text = "Western Cape", Value = "4" });
prov .Add(new SelectListItem { Text = "Limpopo", Value = "5" });
prov .Add(new SelectListItem { Text = "North West", Value = 6});
prov .Add(new SelectListItem { Text = "KwaZulu-Natal", Value = "7" });
prov .Add(new SelectListItem { Text = "Mpumalanga", Value = "8" });
prov .Add(new SelectListItem { Text = "Gauteng", Value = "9" });
//storing provinces in ViewData it will pass them to the view
ViewData["province"] = prop;
return View();
}
// Now you can add your View by right-click on ActionResults method Provinces and you have to select Add View
@using (Html.BeginForm())
{
@Html.DropDownList("Province", ViewData["province"]as List<selectlistitem>)
}