[HttpPost]  //当请求类型为Post的时候由此方法处理请求
 public ActionResult Edit(Album album)
 {
     if (ModelState.IsValid)
     {
         storeDB.Entry(album).State = System.Data.EntityState.Modified;//这个要添加引用
         storeDB.SaveChanges();
         //重定向制定到Index()方法
         return(RedirectToAction("Index"));
     }
     ViewBag.GemreId  = new SelectList(storeDB.Genres, "GenreId", "Name", album.GenreId);
     ViewBag.ArtistId = new SelectList(storeDB.Artists, "ArtistId", "Name", album.ArtistId);
     return(View(album));
 }
Exemplo n.º 2
0
        public ActionResult Edit(Album album)
        {
            if (ModelState.IsValid)
            {
                storeDB.Entry(album).State = System.Data.Entity.EntityState.Modified;
                storeDB.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.GenreId  = new SelectList(storeDB.Genres, "GenreId", "Name", album.GenreId);
            ViewBag.ArtistId = new SelectList(storeDB.Artists, "ArtistId", "Name", album.ArtistId);
            return(View(album));


            //try
            //{

            //    // TODO: Add update logic here
            //    MvcMusicStore.Models.Album album = storeDB.Albums.Find(id);

            //    if (this.TryUpdateModel<MvcMusicStore.Models.Album>(album))
            //    {

            //        return RedirectToAction("Index");

            //    }

            //    return View();

            //}

            //catch
            //{

            //    return View();

            //}
        }