Finally worked..:)
<div class="col-md-8 form-group" style="text-align:right;">
<input type="button" value="Turn Email ON" class="btn btn-success" id="btnturnemailonoff" />
</div>
<div class="col-md-2 form-group">
<input type="checkbox" id="Chkemailonoff" />
</div>
<script type="javascript">
$(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);
debugger;
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");
}
});
});
});
</script>
Update model from the database...
Controller code:
[HttpPost]
public ActionResult CheckEmail(string checkemails)
{
//calling Stored Procedure
if (!string.IsNullOrWhiteSpace(checkemails))
{
var checkemails1 = new SqlParameter("checkemails", checkemails);
db.Database.ExecuteSqlCommand("EXEC Sp_Email_on_off @checkemails", checkemails1);
}
return new JsonResult { };
}
Thank u so much Sir for the Help...highly appreciated...:)