【发布时间】:2019-01-13 19:35:23
【问题描述】:
我是 .net 核心 MVC 的新手,我正在尝试执行类似于 .net 框架 MVC 的 Ajax 帖子。我只是想将一个 int 值发布到下面的控制器操作。 Ajax 调用命中控制器,但 action 参数始终为 0。我验证了在 Ajax 请求负载中发送了正确的整数值。我错过了什么?
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult Ajax_GenerateSecretNum([FromBody]int lower)
{
return Json(new { success = true });
}
$.ajax({
url: '@Url.Action("Ajax_GenerateSecretNum", "Home")',
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: { lower: lower },
success: function (response) {
}
});
【问题讨论】:
标签: c# asp.net-core-mvc asp.net-core-2.1