创建2个下拉菜单和一个基于下拉菜单值的表 [英] Create 2 dropdowns and a table based on the value of the dropdown

查看:69
本文介绍了创建2个下拉菜单和一个基于下拉菜单值的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC3项目(使用C#),并且正在使用Razor和EntityFramework 4.1,我想完成以下任务:
1.创建一个显示省份的下拉列表.选择省份后,它会自动填充第二个下拉列表,显示该省以下的城市.
2.第二个显示城市的下拉菜单(由第一个下拉列表填充),一旦用户选择了城市,它将自动填充一个表格,显示该城市下的郊区.
3.包含郊区列表的表(基于第二个下拉列表).

提前谢谢!

我已经创建了模型,

I have a MVC3 project (using C#) and am using Razor and EntityFramework 4.1 and I''d like to accomplish the following:
1.Create a dropdown that displays provinces. Once you choose a province, it automatically populates a second dropdown that shows the cities under that province.
2.A second dropdown that shows the cities (as populated by the first dropdown), once the user chooses the city, it will automatically populate a table showing the suburbs under the city.
3.A table that contains a list of suburbs (based on the second dropdown).

Thanks in advance!

I''ve created my models,

public class Provinces{
[Key]public int ProvinceID {get; set;}
public string Province {get; set;}
public virtual ICollection<city> City {get;set;}}</city>





public class City{
[Key]public int CityID {get; set;}
public string City {get; set;}
public virtual ICollection<suburb> Suburb {get; set;}
public virtual Province Province {get; set;}}</suburb>





public class Suburb{
[Key]public int SuburbID {get; set;}
public string Suburb {get; set;}
public virtual City City {get; set;}}



一个用于处理下拉菜单的ViewModel



A ViewModel to handle the dropdown

public class MyViewModel{
public string SelectedProvinceID {get; set;}
public string SelectedCityID {get; set;}
public IEnumerable<province> Province {get; set;}}</province>



控制器



A Controller

public class Suburbs : Controller{
MyEntities suburbsDB = new MyEntities();
public ActionResult Create(){ 
//For Province dropdown
ViewBag.Province = suburbsDB.Province.OrderBy(prov => prov.Province).ToList();
var suburbDetails =  new Suburb();
return View(suburbDetails);}



我是EntityFramework,Json和Razor的新手,我对如何创建视图有疑问.
如何根据郊区下拉列表的值刷新表?



I''m quite new to EntityFramework, Json, and Razor and I''m having a problem on how will I create the view.
How can I refresh the table based on the value of the Suburb dropdown?

推荐答案

u可以使用此控件

只需下载dll并使用...这里是链接

http://www.obout.com/combobox/aspnet_master_detail_cascading.aspx [
u can use this control

just download dll and use...here is link

http://www.obout.com/combobox/aspnet_master_detail_cascading.aspx[^]


这篇关于创建2个下拉菜单和一个基于下拉菜单值的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆