ASP.net MVC3 howto edit sql database
Posted
by
user1662380
on Stack Overflow
See other posts from Stack Overflow
or by user1662380
Published on 2012-09-11T09:32:18Z
Indexed on
2012/09/11
9:38 UTC
Read the original article
Hit count: 176
MovieStoreEntities MovieDb = new MovieStoreEntities();
public ActionResult Edit(int id)
{
//var EditMovie1 = MovieDb
AddMovieModel EditMovie = (from M in MovieDb.Movies
from C in MovieDb.Categories
where M.CategoryId == C.Id
where M.Id == id
select new AddMovieModel { Name = M.Name, Director = M.Director, Country = M.Country, categorie = C.CategoryName, Category = M.CategoryId }).FirstOrDefault();
//AddMovieModel EditMovie1 = MovieDb.Movies.Where(m => m.Id == id).Select(m => new AddMovieModel {m.Id }).First();
List<CategoryModel> categories = MovieDb.Categories
.Select(category => new CategoryModel { Category = category.CategoryName, id = category.Id })
.ToList();
ViewBag.Category = new SelectList(categories, "Id", "Category");
return View(EditMovie);
}
//
// POST: /Default1/Edit/5
[HttpPost]
public ActionResult Edit(AddMovieModel Model2)
{
List<CategoryModel> categories = MovieDb.Categories
.Select(category => new CategoryModel { Category = category.CategoryName, id = category.Id })
.ToList();
ViewBag.Category = new SelectList(categories, "Id", "Category");
if (ModelState.IsValid)
{
//MovieStoreEntities model = new MovieStoreEntities();
MovieDb.SaveChanges();
return View("Thanks2", Model2);
}
else
return View();
}
This is the Code that I have wrote to edit Movie details and update database in the sql server. This dont have any compile errors, But It didnt update sql server database.
© Stack Overflow or respective owner