-1
When running my program the following error arises:
>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 be?
**********scheduleDBContext class*******************
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);
}
}
}
inform your context, error, doubt and your searches please.
– Joannis
this is the error that appears what can be?
– Everson Souza de Araujo
Post the C code: course Agenda Agenda Controllers Agendacontroller.Cs
– Guilherme de Jesus Santos
No, you don’t get bored. in the question you should put the context! , that is, explain what your program does, put the error shown, and the code snippet where you think you have the error. type like: http://answall.com/questions/39511/problema-com-conex%C3%A3o-ftp-no-android
– Joannis
as I do, because when I do exceeds the limit
– Everson Souza de Araujo
not in the comment, edit your question (below the tags between share and flag)
– Joannis
using Agendamvc.Models; using System; using System.Web; using System.Web.Mvc; namespace Agendamvc.Controllers { public class Agendacontroller : Controller { Agendadbcontext scheduleContext = new Agendadbcontext(); public Actionresult Insert() { Return View(); } [Httppost] public Actionresult Insert(Schedule) { if(Modelstate.Isvalid) { Try { scheduleContext.Agenda.Add(scheduler); scheduleContext.Savechanges(); Return Json(new { Url = Url.Action("Index"), Message = "Contact Successfully Inserted", Title = "Success" }); } } ; (Exception) { throw; } } Return View(agenda); } } }
– Everson Souza de Araujo
@Eversonsouzadearaujo You can change the question and include the code of the Agendadbcontext class?
– BrenoSarkis