i'm a student and needs to make a application for school. This is a reservation application for a restaurant. I want to create a Create view for the menu where you can give the menu a name and you choose which dishes this menu needs to have. These dishes are stored in another model. I'm using this question: Create a Dropdown List for MVC3 using Entity Framework (.edmx Model) & Razor Views && Insert A Database Record to Multiple Tables but not get it to work. This is my model:
public class MenuAddController
{
private BonTempsDbContext db = new BonTempsDbContext();
public Menu Menu { get; set; }
public Dictionary<int, string> Voorgerechten { get; set; }
public Dictionary<int, string> Hoofdgerechten { get; set; }
public Dictionary<int, string> Nagerechten { get; set; }
public MenuAddController() { }
public MenuAddController(int id)
{
Menu = db.Menu
.Where(e => e.id == id).SingleOrDefault();
// instantiate your dictionaries
foreach (var Voorgerecht in db.Voorgerecht)
{
Voorgerechten.Add(Voorgerecht.id, Voorgerecht.description);
}
foreach (var Hoofdgerecht in db.Hoofdgerecht)
{
Hoofdgerechten.Add(Hoofdgerecht.id, Hoofdgerecht.description);
}
foreach (var Nagerecht in db.Nagerecht)
{
Nagerechten.Add(Nagerecht.id, Nagerecht.description);
}
}
}
And this is my Controller.
public class MenusController : Controller
{
// GET: Menus
public ActionResult Index()
{
return View();
}
[HttpGet]
public ActionResult Add()
{
return View(new MenuAddController());
}
[HttpPost]
public ActionResult Add(MenuAddController vm)
{
if (ModelState.IsValid)
{
Menu.Add(vm.Menu); <--- this is the error line
return View("Index"); // or wherever you go after successful add
}
return View(vm);
}
}
It gives an error on
Menu.Add(vm.Menu);
Error 1 'BonTempsMVC.Menu' does not contain a definition for 'Add'
Anyone can help me with this?