I've a main view having two partial view with same modal one as main address and another as delivery address. I've a checkbox(this is also my delivery address) under main address where on checking that delivery address should be removed from database as well as shouldn't be visible on the view.
Currently the problem that I'm facing right now is in a scenario where, if user click on checkbox when user already had a delivery address before, the delivery address will be removed from db as well as delivery partialview will be hidden. I'm using a jquery to trigger an action to remove from db and hide the delivery partial view. Below is the code for the same:
$('input[type="checkbox"]').on('change', function (e) {
if (e.target.checked) {
// call this if checkbox is checked
$(document).ready(function () {
$('#modal-delivery').modal('show');
});
}
else
{
// call this if checkbox is unchecked
$.post('@Url.Action("DeliveryAddressUpdate", "Address")',
{ data: address, isDeliveryAddressDeleted: true
});
$(document).ready(function () {
//clear the modal here before showing the view
$('#delivery-address').show().find('.btn-edit').click();
//$('button[type="button"]').click();
});
}
});
I've an action in the controller which will be triggered by above jquery, somthing like:
[HttpPost]
public ActionResult DeliveryAddressUpdate(AddressModel data, bool isDeliveryAddressDeleted)
{
UpdateDeliveryAddress(data, isDeliveryAddressDeleted);
}
Now when I uncheck the checkbox, again it will trigger the same jquery and run the else part of it. While showing the delivery address it will still retain the previous delivery address values for some reason. When I refresh the page then it shows blank delivery field. Any idea on this cause.
I tried ModelState.Clear()
but it doesn't work for me.
Any help will be appreciated.