0

I am following this tutorial on how to create a simple database web application with ASP.NET MVC. I am having a problem with the 2nd Create controller method in the home controller (in Listing 4). Specifically, the error - when the web app is built - is with the AddToMovieSet method that actually saves the entries to the database.

It is worth noting that I am using VS 2016, whereas the tutorial uses a much older version (2008); this might be the reason to the problem. But, nevertheless, what is the code for this Create controller method?

This is the code in the Create action method in the home controller:

public ActionResult Create(Movie movieToCreate)
{
     if (!ModelState.IsValid)
        return View(); 

    _db.AddToMovieSet(movieToCreate);
    _db.SaveChanges(); 

    return RedirectToAction("Index");
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Are you trying to create a new Movie and save it to the database? What exactly are you trying to accomplish? I'm not understanding what exactly the problem you are having. – Jasen Aug 09 '17 at 17:31
  • Yes, I am trying to add a movie and save it to the database. – Mahmoud Hamad Aug 09 '17 at 17:32
  • Also, that appears to be a MVC1 tutorial. You'll probably have a better experience with a newer one https://learn.microsoft.com/en-us/aspnet/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application. MVC4 is still much like MVC5. And the Entity Framework version changes are also significant. – Jasen Aug 09 '17 at 17:35
  • @Jasen, the thing is, as a beginner, I found MVC1 much more straight forward than MVC4. Is there a way to adapt the latter to the former in this instance? – Mahmoud Hamad Aug 09 '17 at 17:41
  • This one is closer to the movie theme https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/ and also newer. The major difficulty with the MVC1 tutorial is the EF changes. – Jasen Aug 09 '17 at 17:44
  • No matter the version.. your question is very unclear. What **exactly** is the problem you're experiencing? – Grizzly Aug 09 '17 at 18:11

1 Answers1

0

Make sure you have proper view created for this action method. Else create view or return view explicitly with name.