i've got bit of issue, I've got three models:
model - City
public int ID{get;set;}
public String Name { get; set; }
model - Suburb
public int ID { get; set; }
public int CityId {get;set;}
public string Name { get; set; }
public String Description { get; set; }
public virtual ICollection<City> Cities { get; set; }
model- CitySuburbContext
public DbSet<City> City { get; set; }
public DbSet<Suburb> Suburb { get; set; }
This is my controller:
public ActionResult Index()
{
return View("Index",db.Suburb.ToList());
}
public ActionResult getSuburb(int id)
{
return Json(db.Suburb.Where(s => s.ID.Equals(id)).ToList(), JsonRequestBehavior.AllowGet);
}
THIS IS MY VIEW (now)
@model Admin.Models.Suburb
<header>
<script src="~/Scripts/dddd.js" type="text/javascript"></script>
</header>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@Html.DropDownListFor(m => m.CityId, new SelectList( ((List<SelectListItem>)ViewData["cities"]),"Value","Text"), new { @onChange = "fillSuburb()" })
@Html.DropDownListFor(m => m.ID, Enumerable.Empty<SelectListItem>())
My issue is.
How do i get data in my view. Do i use the CitySuburbContext model? if so how?
Also i want 2 dropdownlist, one with list of cities and another list of suburbs for the selected city. I am not sure how to tackle this, some one please help