// GET: Cities/Create public ActionResult Create() { EditOrCreateCityViewModel model = new EditOrCreateCityViewModel() { Countries = new SelectList(db.Countries, "Id", "Name") }; return(View(model)); }
public ActionResult Edit([Bind(Include = "Id,Name,CountryId")] City city) { if (ModelState.IsValid) { db.Entry(city).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } EditOrCreateCityViewModel model = new EditOrCreateCityViewModel() { City = city, Countries = new SelectList(db.Countries, "Id", "Name") }; return(View(model)); }
// GET: Cities/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } City city = db.Cities.Find(id); if (city == null) { return(HttpNotFound()); } EditOrCreateCityViewModel model = new EditOrCreateCityViewModel() { City = city, Countries = new SelectList(db.Countries, "Id", "Name") }; return(View(model)); }