Your error is related to the fact that MenusController does not have a Menu property, i.e. You have not announced anything called Menu . It looks like you are trying to use the Menu object in MenuAddController, but it clearly does not exist in MenusController, since this is a completely different class.
By the names of your classes, you may not fully grasp the MVC pattern. Your MenuAddController looks like it is trying to be a view model and possibly a repository - I canβt say exactly what your intention is. The good news is MenusController . The only thing that he lacks is a way to save / save the menu (adding things) to the database.
Let's start with the MenusController , as you seem to be closest to completion. As already mentioned, data access is all that is missing. I would like to add the BonTempsDbContext property to the controller class, or at least create an instance inside the Add (POST) action, for example.
public class MenusController { private BonTempsDbContext db = new BonTempsDbContext();
or in the action itself, for example
[HttpPost] public ActionResult Add(SomeViewModel vm) { var db = new BonTempsDbContext();
The only other weirdness that I see is the GET Add action. Your variable name suggests that you pass it a controller, which does not make sense in the context of MVC. The congress that I see most often is to pass an empty view model object (described just below) to set up a form for publication in the POST version of the action.
This is not complete (like pseudo-code) as you mentioned homework!
Now for the rest of the bits. MenuAddController does not make any sense (for me) as an object or name, so consider a new object called MenuAddViewModel , which represents the state of the added Menu object, i.e. an ASP.NET MVC object will be bound for you when the user submits a form (which you did not show). Perhaps there is a Menu property on the specified object of the view model and what you plan to save in the database, for example
public class MenuAddViewModel { public Menu Menu { get; set; }
It can be that simple if your form is generated in such a way that MVC can automatically bind the Menu property. That way, you can reuse (almost always well) the MenuAddViewModel object in your Add actions. You pass it to the GET view, and it helps to fill in the blank form, then the user submits (POST) to the post and POOF views, the data context can save it in the database or wherever it is.
The new view model object that I am describing will not need a data context object because it only needs to know the state of the Menu object. If you need to combine menu items, you can add properties to the specified view model object and go from there.