I have a code in index.cshtml
@using (@Ajax.BeginForm("ActionEvent", "Fielding", new AjaxOptions { OnSuccess = "onBDSuccessFunction", HttpMethod = "post" }, new { id = "frmField" }))
{
@Html.Partial("../Fielding/_CreateOrEdit", Model)
}
and in _CreateOrEdit
function onBDSuccessFunction(result, status, xhr) {
var errorMessage = '';
switch (String(result.Result).toUpperCase()) **2 cases from controller when Actionevent Method fired** {
case "OK":
var _msg = "Data Saved Successfully";
alert(_msg);
return true; **saved data into database only happens here**
break;
case "ERROR":
if(result.Message=='1')
{
alert(result.Messag);
return false; **prevent submiting form here**
}
}
}
Here i have 2 cases from ActionEvent Method Case OK and Case ERROR it returns result as Json
- If Controller returns Case OK I want to save the entered details in the form into database
- If Controller returns Case ERROR I dont want to save the entered details in the form into database
But in both cases the data saved into database .. but the validation fired message shows correctly.. What can i do for this.. please guide me..