I’m trying the following:
$("#button_feedback").click(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: $('#button_feedback').data('url'),
data: "{message: " + $('#feedback_content_wrapper textarea').val() + " }",
dataType: "json",
success: function (data) {
alert(data);
}
});
});
<input type="button" value="Enviar" class="button" id="button_feedback" data-url="@Url.Action("SendMail", "Contacto")"/>
And in my controller:
public class ContactoController : Controller
{
...
public ActionResult Send_Mail(string message)
{
return Json(new { mensaje = "Correo enviado con éxito" });
}
}
However I keep getting:
POST http://localhost:11280/Contacto/SendMail404 Not Found
Why? Everything seems correct!!!…
Your method name has an underscore. Either change your method name or modify the action in the UrlHelper to match with the underscore.