I’m new to ASP.net, MVC, C# and I’m working on a project that requires me to delete a person from a database. The table has been specifically setup to accommodate adding and deleting users as there will be a small number of people using this particular application.
I’m having trouble understanding where the Controller Post function gets its parameters from.
My controller contains:
public ActionResult DeleteUser()
{
return View(new tblPermission());
}
[HttpPost]
public ActionResult DeleteUser(int? id)
{
if(id == null)
{
return View(id);
}
Permission.DeleteUser((int)id);
return RedirectToAction("AdminIndex");
}
When I test this function, I’m always hitting the id == null condition because I’m not passing in the id. What confuses me is, how do I get the user ID to pass it into this function call? Do I need to get this information and pass it in, in my view layer?
This is my view layer:
@model MAA_v2.Models.tblPermission
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"> </script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Remove</legend>
<p>
<input type="submit" value="Remove" name="Remove" class="button action-button " />
@Html.ActionLink("Back", "AdminIndex", "Maintenance", new { @class = "button action-button" })
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to Admin Maintenance", "AdminIndex")
</div>
Value is being passed from the http form, for example