コード例 #1
0
        public ActionResult Create([Bind(Include = "CategoryId,CategoryName")] CategoryCreateViewModel category, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                Category cat = new Category();
                cat.CategoryName = category.CategoryName;

                db.Categories.Add(cat);
                db.SaveChanges();
                return RedirectToAction("Index","Settings");
            }

            return View(category);
        }
コード例 #2
0
        public ActionResult Edit([Bind(Include = "CategoryId,CategoryName")] CategoryEditViewModel category, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                Category cat = new Category();
                cat.CategoryId = category.CategoryId;
                cat.CategoryName = category.CategoryName;

                db.Entry(cat).State = EntityState.Modified;
                db.SaveChanges();
                return Redirect(returnUrl);
            }
            return View(category);
        }