i have looked around and seen that alot of people have had this problem. However mine is not exactly the same. While the other problems are typically solved by using correct overloads of the ActionLink Method, and fixed by making sure that the recieved object type in the method is correct, this is not the came.
In this example code, the variables are all set correct according to all other sources, however the user object recieved in the method is always null.
What i have done:
- Checked if the object put onto the ActionLink has data (it does)
- Checked if the Type of the object i received is correct, along with the one i send
- Tried using Ajax ActionLink and HttpPost Method instead
Here is the code first from backend and then frontend
public void DeleteUser(User user)
{
using (EFEntity context = new EFEntity())
{
context.User.Attach(user);
context.User.Remove(user);
context.SaveChanges();
Response.Redirect("~/Home/someView");
}
}
Action Link Front end:
foreach (User user in Model.userList)
{
<tr>
<td>
@{
number = number + 1;
}
@number
</td>
<td>@user.Gid</td>
<td>@user.Name</td>
<td>@user.Email</td>
<td>@user.Permissions.Perm</td>
<td>@user.LastUpdated</td>
<td>
@Html.ActionLink("Delete", "DeleteUser", "Service", user, new { @class = "btn btn-danger" })
</td>
</tr>
}