I have tried these two ways.
1
[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id)// el id llega con toda normalidad
{
db.Entry(db.Detalle.Find(id)).State = EntityState.Deleted;
db.SaveChanges();
return RedirectToAction("Index");
}
2
[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id) // el id llega con toda normalidad
{
Detalle idar = db.Detalle.Find(id);
db.Detalle.Remove(idar);
db.SaveChanges();
return RedirectToAction("Index");
}
and both give me the same error
User code did not handle System.ArgumentNullException HResult=-2147467261 Message=Value cannot be null. Parameter name: entity ParamName=entity Source=EntityFramework StackTrace: at System.Data.Entity.ModelConfiguration.Utilities.RuntimeFailureMethods.Requires(Boolean condition, String userMessage, String conditionText) at System.Data.Entity.DbSet
1.Remove(TEntity entity) en SIGA.net.Controllers.ArqueoController.DeleteConfirmed(Int32 id) en C:\Proyectos\SIGA.net\SIGA.net\Controllers\ArqueoController.cs:línea 173 en lambda_method(Closure , ControllerBase , Object[] ) en System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) en System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary
2 parameters) at System .Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) en System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() en System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8
1.b__7(IAsyncResult _) in System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() in System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) in System.Web.Mvc.Async. AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.b__33() in System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.b__49() InnerException:
don't use linq, use it this way and you'll be happy..
you can try on the line
db.Detalle.Find
with db.Detail.FirstOrDefault although in this case I think it's betterdb.Detalle.SingleOrDefault
or simply db.Detail.Single reference difference between single find and firstorDefaultry and see how it goes