I would like to control when to reply an error message and when a success message but I am always get the error message:
here is what I am trying to do:
$.ajax({
type: "POST",
data: formData,
url: "/Forms/GetJobData",
dataType: 'json',
contentType: false,
processData: false,
success: function (response) {
alert("success!")
},
error: function (response) {
alert("error") // I'm always get this.
}
});
Controller:
[HttpPost]
public ActionResult GetJobData(Jobs jobData)
{
var mimeType = jobData.File.ContentType;
var isFileSupported = AllowedMimeTypes(mimeType);
if (!isFileSupported){
// Error
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Content("The attached file is not supported", MediaTypeNames.Text.Plain);
}
else
{
// Success
Response.StatusCode = (int)HttpStatusCode.OK;
return Content("Message sent!", MediaTypeNames.Text.Plain);
}
}