s

asp .net mvc exception The parameters dictionary contains a null entry for parameter id of non-nullable type edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 08 September 2020 | 0

The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Guid' for method 'System.Web.Mvc.ActionResult Edit(System.Guid)' in 'YourAppName.Web.Controllers.YourController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Guid' for method 'System.Web.Mvc.ActionResult Edit(System.Guid)' in 'Beginner.Web.Controllers.RecipeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Solution

This error happens when the controller action method requires the parameter of type unique identifier and no parameter or null or different type of parameter is passed to the action method
I got this error while I was trying to redirect to the edit method from the create method
the problem was with the code below

   

return RedirectToAction("Edit", "Recipe", recipe.Id);


the solution was to correct the syntax and pass id
  

return RedirectToAction("Edit", "Recipe", new { id = recipe.Id } );