Modifying Genre Controller (2)

There is a new way while submitting an item with LINQ to SQL method.

Genre genre = new Genre()
{
    Name = model.Name
};

context.Genres.InsertOnSubmit(genre);
context.SubmitChanges();
return RedirectToAction("Index");

The final code should look like this.

[HttpPost]
public ActionResult Create(GenreModel model)
{
    try
    {
        Genre genre = new Genre()
        {
            Name = model.Name
        };

        context.Genres.InsertOnSubmit(genre);
        context.SubmitChanges();
        return RedirectToAction("Index");
    }
    catch
    {
        return View(model);
    }
}

results matching ""

    No results matching ""