I wanted to write condition for confirmation box such that : There is a button: Turn on email.
So when user click on it,it becomes turn off email and sends status as true.
when i again click on turn off email,it becomes turn on email and sends status as false.
I wanted to write condition for confirmation box such that :
when user click on turn on button,confirmation box should come like Do you want to turn on the email? if yes,it should change to turn off button and sends status to controller(true) and if no,it stays as it is.
It becomes turn off button(when we click on yes).So when i click aagin on turn off button,confirmation box should come like Do you want to turn off the email? if yes,it should change to turn on button and sends status to controller(false) and if no, it stays as it is.
$(document).ready(function () {
$('#btnturnemailonoff').on('click', function () {
var checked = !$(this).data('checked');
$("#Chkemailonoff").prop('checked', checked);
$(this).val(checked ? 'Turn Email Off' : 'Turn Email on')
$(this).data('checked', checked);
//if (confirm("Do you want to turn on the email?")) {
// checked.val("true");
//} else {
// checked.val("false");
//}
var url = '@Url.Action("CheckEmail", "BillingDetails")';
$.ajax({
url: url,
type: "POST",
data: { checkemails: checked },
dataType: "json",
// traditional: true,
success: function () {
alert("ajax request to server succeed");
}
});
});
});
[HttpPost]
public ActionResult CheckEmail(string checkemails)
{
//calling Stored Procedure
if (!string.IsNullOrWhiteSpace(checkemails)|| checkemails=="true" || checkemails=="false")
{
var checkemails1 = new SqlParameter("checkemails", checkemails);
db.Database.ExecuteSqlCommand("EXEC Sp_Email_on_off @checkemails", checkemails1);
}
return new JsonResult { };
}