Im including the popular file jquery.form.js. I have the following:
var options = {
beforeSubmit: beforeSubmit, // pre-submit callback
success: afterSubmit // post-submit callback
};
$('#myForm').submit(function (e) {
$(this).ajaxSubmit(options);
return false;
});
function afterSubmit(responseText, statusText, xhr, $form) {
// i want to check for an error
}
I call this action:
[HttpPost]
public string UploadDocument(DocumentModel model)
{
if (noerror)
return "ok";
else
return "the error";
}
Somewhere in the parameters ‘responseText, statusText, xhr, $form’ the return string is stored.
Where is my return string stored, or how do i store it, so i can check the results when the ‘afterSubmit’ javascript function is called? Thanks
Never return strings from controller actions. In ASP.NET MVC controller actions should return ActionResults:
and then the result will be stored in the
responseTextvariable.Obviously testing in your javascript
if (responseText == 'ok')seems like something absolutely horrible and for this reason there’s JSON:so that in your javascript you could work directly with the underlying types (boolean in this case):