$("#frmCompose").submit(function () {
$(this).ajaxSubmit({
success: function (response) {
alert('success');
}
});
});
Controller code:
[HttpPost]
public ActionResult SendEmail(EmailMessageModel emailMessage)
{
try
{
// do something with the data
return Json(new StatusModel { error = false });
}
catch (Exception)
{
return Json(new StatusModel { error = true, message = "Could not send email" });
}
}
View Code:
<form id="frmCompose" method="post" action="SendEmail">
<button id="compose" class="btn-pencil">
Send</button>
<div class="fields-inline">
<div class="editor-label">
@Html.Label("To:")
</div>
@Html.TextBox("txtTo")
</div>
<div class="fields-inline">
<div class="editor-label">
@Html.Label("Subject:")
</div>
@Html.TextBox("txtSubject")
</div>
<div class="fields-inline">
<div class="editor-label">
@Html.Label("Body:")
</div>
@Html.TextArea("txtBody")
</div>
</form>
In my controller I return a JSon result with a text message.
Why does the view in FireFox want to download the json as a file download?
All I want to do is ensure I get a response within the success callback
Solution is to return false within the submit() call function for the form.
That way, the json result is consumed within the submit function and not passed to the browser for handling.