コード例 #1
0
        // GET: Cities/Create
        public ActionResult Create()
        {
            EditOrCreateCityViewModel model = new EditOrCreateCityViewModel()
            {
                Countries = new SelectList(db.Countries, "Id", "Name")
            };

            return(View(model));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        // 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));
        }