if ( the resource already exists in db) { return new HttpStatusCodeResult( HttpStatusCode. which will trigger the error AJAX. HttpPost] public ActionResult UpdateUser( UserInformation model) { if (! UserIsAuthorized( ) ) return new HttpStatusCodeResult( 401, " Custom Error Message 1" ) ; / / Unauthorized if (! IsValid) return new. AllowGet) ; } else { / / Send " Success" return Json( new { success = true, responseText= " Your message successfuly sent! When I want to return an error : if (! isFileSupported) { Response. StatusCode = ( int) HttpStatusCode. This is where HTTP status codes come into play. With Ajax you will be able to handle them accordingly. [ HttpPost] public ActionResult UpdateUser( UserInformation model) { if (! UserIsAuthorized( ) ) return new.
jondavidjohn is right on the dot. However, to get the validation, you need to return the validation_ errors( ) via ajax: You will need to have some place where you put in the validation errors: HTML < div class= " errors" > < / div>. I was able to resolve it by changing the controller action return type as Action Result and then use Json object to return data what i want to - For example [ AcceptVerbs( HttpVerbs. Post) ] public ActionResult. If you returns a json object ( as business model error) the javascript data value ( which has the request result) will never be null. You can try an approach like this: C# [ HttpGet] public ActionResult GetDetailPG( string pgId). Wrap everything in try catch. You can simple call the JSON method which will create a JSON response and return that to the client code. Also, you do not need JsonRequestBehavior. AllowGet to return JSON when it is a.