Я хочу, чтобы он вызывал запрос на отправку контроллеру, расположенному в Project/ Контроллеры/TestEmailSenderController
Я пробовал все, что угодно, но что бы я ни делал, он просто возвращает ошибку 404.
Мой последний тест выглядит так: как показано ниже:
Ajax-запрос:
Код: Выделить всё
$.ajax({
type: 'post',
url: '/Controllers/TestEmailSender/Send',
contentType: 'application/json',
data: { "EmailInfo": inner }
});
Код: Выделить всё
[Route("Controllers/[controller]")]
public class TestEmailSenderController : Controller
{
public IActionResult Index()
{
return View();
}
[HttpPost]
[Route("Send")]
public ActionResult Send(string EmailInfo)
{
//Action code
}
}
РЕДАКТИРОВАТЬ
Я заставил это работать, добавив следующее в мой StartupCS
Код: Выделить всё
endpoints.MapControllerRoute(
name: "default",
pattern: "Controllers/{controller=Home}/{action=Index}/{id?}");
Код: Выделить всё
[Route("Controllers/[controller]/[Action]")]
public class TestEmailSenderController : Controller
{
public IActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Send([FromBody]EmailInfo EmailInfo)
{
//Action
}
}
Код: Выделить всё
$.ajax({
type: 'post',
url: '/Controllers/TestEmailSender/Send',
contentType: 'application/json',
data: { inner }
});
Подробнее здесь: https://stackoverflow.com/questions/786 ... -not-found