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
- public static int DeleteUserDetails( int id )
- {
- int rowAffected = 0;
- using (IDbConnection con = new SqlConnection(ConnectionString))
- {
- if (con.State == ConnectionState.Closed)
- con.Open();
- DynamicParameters parameters = new DynamicParameters();
- parameters.Add("@Id", id);
- rowAffected = con.Execute("DeleteGroupMeeting", parameters, commandType: CommandType.StoredProcedure);
- }
- return rowAffected;
- }
This is the controller part
- public ActionResult DeleteUserDetails( int id,UserModel usermodel)
- {
- if(UserModel.DeleteUserDetails(id)>0)
- {
- return RedirectToAction("Dashboard", "Home");
- }
- return RedirectToAction("Dashboard", "Home");
- }
this is code for button
- <a href="@Url.Action("DeleteUserDetails","Account", new {item.UserId})">Delete</a>