public ActionResult Create(RoomCreateViewModel roomCreateViewModel) { if (ModelState.IsValid) { Room room = new Room { Name = roomCreateViewModel.Name, FloorId = roomCreateViewModel.FloorId }; this.Data.Rooms.Add(room); this.Data.SaveChanges(); return RedirectToAction("List", "Rooms", new { FloorId = roomCreateViewModel.FloorId }); } return View(roomCreateViewModel); }
public ActionResult Create(int? floorId) { if (floorId == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Floor floor=this.Data.Floors.GetById(floorId.Value); if (floor == null) { return HttpNotFound(); } RoomCreateViewModel roomCreateViewModel = new RoomCreateViewModel { FloorId = floorId.Value, }; return View(roomCreateViewModel); }