I am trying to delete a row from database in asp.net MVC C# using the code below
[HttpGet]
public ActionResult Delete(Guid TeleGUID)
{
oyetriviadbEntities db = new oyetriviadbEntities();
TeleInfo oTeleInfo = db.TeleInfoes.Find(TeleGUID);
return View(oTeleInfo);
}
[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(Guid TeleGUID)
{
oyetriviadbEntities db = new oyetriviadbEntities();
TeleInfo oTeleInfo = db.TeleInfoes.Find(TeleGUID);
db.TeleInfoes.Remove(oTeleInfo);
db.SaveChanges();
return RedirectToAction("TeleList");
}
but executing the above code gives me an error:
The parameters dictionary contains a null entry for parameter 'TeleGUID' of non-nullable type 'System.Guid' for method 'System.Web.Mvc.ActionResult Delete(System.Guid)' in 'MvcApplication3.Controllers.FrancController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
You are not passing the Guid to your ActionMethod which is required(Mandatory) for ActionMethod to execute successfully, read your error again, I am highlighting the important part
The parameters dictionary contains a null entry for parameter 'TeleGUID' of non-nullable type 'System.Guid' for method 'System.Web.Mvc.ActionResult Delete(System.Guid)' in 'MvcApplication3.Controllers.FrancController'
as per the above message you need to pass Guid TeleGUID
value to the controller from View
Note: While you execute the above function of removing a row, the table from which you are removing a row must not have column which is
Primary key
of any other table, otherwise it will throw a new error
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly