I have an ajax.beginform() like this :
@using (Ajax.BeginForm("Create_Product", "Admin", new AjaxOptions() { OnFailure = "alert(\"Error !!!\")", HttpMethod = "post"}))
{
//blah blah
}
It sends the form data to an ActionMethod called Create_Product…
Inside this ActionMethod, before I save the data as a new ‘product’ to the database, – inside a try/catch – I check to see whether the inserted product already exists or not. And if already exists, I need to return to the view AND trigger/run the OnFailure method of the ajax form 🙂
Is it possible ? how is it done ?
Remove the Ajax Beginform and use the normal form
And some javascript now to handle our Ajax Saving
Assuming your Action method Returns a
JSONback in the below format, if it is successfully insertedIf the Product already exist, It returns this
So your Action method can look like this