I currently have panels and each panel has an ID associated with it which is held in the data-id attribute of each panel. I can get this easily through JavaScript. One the panels I have a delete button which will delete the panel and it's entry within the database. Once this delete button is clicked, a modal will fire up with a Html.BeginForm() which is hooked up to an action on my controller. I was wondering if it was possible to add an the widget ID to the routing values via JavaScript?
Here is my modal:
<div class="modal fade" id="deleteWidgetModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Delete widget?</h4><!--add depending on which panel you have clicked-->
</div>
<div class="modal-body" id="myModalBody">
<!--Depending on which panel insert content-->
@using (Html.BeginForm("DeleteWidgetConfirmed", "Dashboard", FormMethod.Post,))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
Do you wish to delete this widget?
<div class="form-group">
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" value="DeleteWidgetConfirmed" class="btn btn-danger btn-ok" id="delete-widget">Delete</button>
</div>
</div>
</div>
}
</div>
</div>
</div>
and here is the JavaScript:
/*---------------------------------------------DELETING PANELS-------------------------------------------------*/
$(document).ready(function () {
$('#columns').on('click', '.glyphicon.glyphicon-trash', function (event) {
//get id here
//toggle the modal
$('#deleteWidgetModal').modal('toggle');
//pass id to form
});
});
$(document).ready(function () {
document.getElementById('#delete-widget').onclick = function (event) {
event.preventDefault();
var parentElement = $(this).closest(".col-md-4.column");
var targetElement = $(this).closest(".panel.panel-default");
targetElement.remove();
//parentElement.addClass("expand-panel");
checkEmptyPanelContainers();
}
});