I'm new to ASP.NET MVC and I have an app where on the admin page I display a list of users stored in a database, each with their own delete button.
When this delete button is clicked for a specific user, a modal pops up to ask if the admin is sure they want to delete the user. On clicking the confirm button @Url.Action("DeleteUser", "Home" , new { UserID = id })
needs to be called (where id is the selected user's id) but I don't know how to pass the user id from the delete button to the modal in order to delete the relevant user.
Delete Button:
delete button html
<button type="button" class="btn btn-info btn-lg right-float-button"
value=Model.Users[i].ID data-toggle="modal"
data-target="#deleteUser">Delete User</button>
(the Model.Users[i].ID is an int for the current user's id)
Modal: delete user modal
<!-- Modal -->
<div class="modal fade" id="deleteUser" role="alert">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Delete User</h4>
</div>
<div class="modal-body">
<p>Are you sure?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button onclick="location.href='@Url.Action("DeleteUser", "Home" , new { UserID = ?? })'"
type="submit" class="btn btn-default">Delete</button>
</div>
</div>
</div>
</div>
How can I pass Model.Users[i].ID to the modal to be used in the Url.Action where the "??" are?