我創造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