removing a particular row from the table using MVC C# throws an error


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


Asked by:- Aiswarjya
2
: 3791 At:- 9/19/2017 6:03:42 AM
asp.net mvc removing-row delete







1 Answers
profileImage Answered by:- pika

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

2
At:- 9/19/2017 7:35:43 AM Updated at:- 9/19/2017 7:43:00 AM
passing the value like this code @Html.ActionLink("Delete", "Delete", new { id = item.TeleGUID }, new { onclick = "return confirm('Are you sure you want to delete this??');" }) 0
By : Aiswarjya - at :- 9/19/2017 8:21:40 AM
It should be changed from @Html.ActionLink("Delete", "Delete", new { id = item.TeleGUID }, new { onclick = "return confirm('Are you sure you want to delete this??');" }) to @Html.ActionLink("Delete", "Delete", new { TeleGUID = item.TeleGUID }, new { onclick = "return confirm('Are you sure you want to delete this??');" }) 1
By : Aiswarjya - at :- 9/19/2017 8:47:19 AM
great, thanks for letting me know 0
By : pika - at :- 9/19/2017 10:41:45 AM
@pika's answer is correct you needto pass Guid properly to your controller 0
By : Sam - at :- 9/19/2017 4:51:17 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use