yash patel

yash patel

  • 1.5k
  • 284
  • 21.1k

The parameters dictionary contains a null entry for parameter 'id'

Oct 16 2020 4:43 AM
m getting the below error when I delete a record from the table in mvc
 
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult DeleteUserDetails(Int32, nsroute.DataAccess.UserModel)' in 'nnnnn.Controllers.AccountController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
 
This is a method for delete
  1. public static int DeleteUserDetails( int id )  
  2. {  
  3. int rowAffected = 0;  
  4. using (IDbConnection con = new SqlConnection(ConnectionString))  
  5. {  
  6. if (con.State == ConnectionState.Closed)  
  7. con.Open();  
  8. DynamicParameters parameters = new DynamicParameters();  
  9. parameters.Add("@Id", id);  
  10. rowAffected = con.Execute("DeleteGroupMeeting", parameters, commandType: CommandType.StoredProcedure);  
  11. }  
  12. return rowAffected;  
  13. }  
This is the controller part
  1. public ActionResult DeleteUserDetails( int id,UserModel usermodel)  
  2. {  
  3. if(UserModel.DeleteUserDetails(id)>0)  
  4. {  
  5. return RedirectToAction("Dashboard""Home");  
  6. }  
  7. return RedirectToAction("Dashboard""Home");  
  8. }  
this is code for button
  1. <a href="@Url.Action("DeleteUserDetails","Account", new {item.UserId})">Delete</a>  

Answers (1)