I am trying to submit a form through an ajax process :
@using (Ajax.BeginForm("SendEmail", "Form", new AjaxOptions
{
UpdateTargetId = "replace",
InsertionMode = InsertionMode.Replace,
HttpMethod = "Post",
}))
{
// the form details
}
the action for this form is defined in the Form controller as:
[HttpPost]
public ActionResult SendEmail(EnquiryFormViewModel model)
{
_sendForm.SendFormByEmail(model.FirstName, model.Surname, model.Email, model.NatureOfEnquiry,model.Message);
return PartialView("EmailResult", model.FormMetaData);
}
The route is defined in the global.asax as:
//Form button
routes.MapRoute(
name: "FormButton",
url: "Form/{action}",
defaults: new { controller = "Form", action = "SendEmail" }
).DataTokens.Add("area", "Core");
The action is supposed to return a partial page that contains some information about the successful submission of the form and thanking the user. However, as soon as the button is clicked, I get a 404 error that Requested URL: /Form/SendEmail is not available. The action method is executed, but I can't get the page that I am supposed to get through the action. How can I fix this?