I want to pass int value from controller and check if it is greater than 0 in $.ajax. I don't know how to do it. I have tried a code but it is giving me undefined value. Going data in controller is working fine. But returning int value not able to do.:
AJAX Code:
function bindForm(dialog,urlString) {
$('form', dialog).submit(function () {
var data_send = $(this).serializeArray();
$.ajax({
url: urlString,
type: this.method,
data: $(this).serialize(),
success: function (result) {
alert(result.success);
if (parseInt(result.success, 10) > 0) {
alert('Details Added Successfully');
$('#dialog-form').dialog('close');
var hdnInvoiceId = document.getElementById("Invoice_Id");
hdnInvoiceId.value = parseInt(result.success, 10);
$('#addInvoiceDetail').hide();
} else {
alert('Please Re-enter Details');
bindForm();
}
}
});
return false;
});
Controller Code:
[HttpPost]
public int AddInvoice(Invoice model)
{
int Invoice_Id = CRMServiceDL.insertInvoiceDetail(model);
int success;
if (Invoice_Id > 0)
{
success = Invoice_Id;
}
else {
success = -1;
}
return success;
}