When I run my program, the following error occurs:
>Error 1 'AgendaMVC.Models.AgendaDBContext' does not contain a definition
for 'Agenda' and no extension method 'Agenda' accepting a first argument
of type
'AgendaMVC.Models.AgendaDBContext' could be found (are you missing a
using directive or an assembly reference?)
C:\curso\Agenda\Agenda\Controllers\AgendaController.cs 33 35 Agenda
What can it be?
********** class agendaDBContext *******************
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using AgendaMVC.Models;
namespace AgendaMVC.Models
{
public class AgendaDBContext : DbContext
{
public AgendaDBContext() :base("name=AgendaDBContext")
{
}
DbSet Agendas { get; set; }
}
}
Controller:
using AgendaMVC.Models;
using System;
using System.Web.Mvc;
namespace AgendaMVC.Controllers
{
public class AgendaController : Controller
{
AgendaDBContext agendaContext = new AgendaDBContext();
public ActionResult Index()
{
return View();
}
public ActionResult Inserir()
{
return View();
}
[HttpPost]
public ActionResult Inserir(Agenda agenda)
{
if (ModelState.IsValid)
{
try
{
agendaContext.Agenda.Add(agenda);//o problema esta aqui agendaContext //nao reconhece a agenda
agendaContext.SaveChanges();
return Json(new
{
Url = Url.Action("Index"),
Mensagem = "Contato Inserido com sucesso",
Titulo = "Sucesso"
});
}
catch (Exception) {
throw;
}
}
return View(agenda);
}
}
}