我创造MVC3搜索应用程序,我有2个表:ID(PK),S_ID(FK),District_name如何使用MVC3在下拉列表中显示数据?
我: 1.State:ID(PK)和STATE_NAME 2.District首先使用代码和EF和具有数据库创建了它所谓的搜索
我希望我的索引显示在下拉所有状态下拉列表
以下是我State.cs代码
public partial class State
{
public State()
{
this.Districts = new HashSet<District>();
this.Search_master = new HashSet<Search_master>();
}
public int Id { get; set; }
public string State_name { get; set; }
public virtual ICollection<District> Districts { get; set; }}
这是我区等级:
public partial class District
{
public District()
{
this.Search_master = new HashSet<Search_master>();
}
public int Id { get; set; }
public string District_name { get; set; }
public int StateId { get; set; }
public virtual State State { get; set; } }
我还为国家及地区的一个视图模型....
public class State_district
{
public string selectedstate { get; set; }
public IEnumerable<State> states { get; set; }
public string selecteddistrict { get; set; }
public IEnumerable<District> districts { get; set; }
}
内部控制我写了:
public ActionResult Index()
{
var model = new State_district { states = db.States, districts = db.Districts };
return View(model);}
视图:
<div class="editor-field" id="districtID">*Select State:-
@Html.DropDownListFor(x => x.states, new SelectList(Model.states, "Id", "State_Name"))
</div>
With这我能够看到我的第一ddl,但我怎么能绑定它与我的第二个名单.....
我需要的代码,帮助我只显示选定的状态区.....只要任何人帮助我与jQuery代码...
谢谢你提前!
http://stackoverflow.com/questions/5096204/how-do-i-use-the-dropdownlist-in-asp-net-mvc-3 http://stackoverflow.com/questions/5098848/help-我明白了解如何工作与dropdownlistfor-in-mvc3 – Henry 2012-03-06 07:16:20
@HenryP:thnx帮助我..... bt我们不能使用sum事物而不是视图模型....我的意思是它需要创建它.... – EqEdi 2012-03-06 08:39:34
@亨利普:链接你给工作以及bt不给我解决方案....可以ü帮助我与总和代码....我已更新我的代码 – EqEdi 2012-03-07 10:42:55