I'm creating a search application in mvc3 where i have 2 tables : 1.State :Id(pk) and state_name 2.District:Id(pk),s_id(f.k.), District_name
I am using code first and EF and have database created for it called Search
I want my index to show all states in drop down list
following is my State.cs code
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; }}
this is my District class:
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; } }
I also created one viewmodel for state and district....
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; }
}
inside controller i have written:
public ActionResult Index()
{
var model = new State_district { states = db.States, districts = db.Districts };
return View(model);}
in the view:
<div class="editor-field" id="districtID">*Select State:-
@Html.DropDownListFor(x => x.states, new SelectList(Model.states, "Id", "State_Name"))
</div>
With this i am able to see my 1st ddl but how can i bind it with my second list.....
I need code that help me to show me district from selected state only.....can anybody help me with the jQuery code...
thank you in advance!!