コード例 #1
0
        public ActionResult Create([Bind(Include = "Id,Text")] Document document)
        {
            if (ModelState.IsValid)
            {
                db.Documents.Add(new Document(document.Text));
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(document));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "Id,Text,CategoryId")] Document document)
        {
            if (ModelState.IsValid)
            {
                db.Documents.Add(new Document(document.Text));
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", document.CategoryId);
            return(View(document));
        }