【问题标题】:POST http://localhost:55703/ValidStep1 404 (Not Found)POST http://localhost:55703/ValidStep1 404(未找到)
【发布时间】:2021-03-09 07:25:36
【问题描述】:

当我点击一个按钮时,我想转到另一个页面,但是当我点击时,什么也没有发生并且我卡在初始页面上 + 我有这个错误:

POST http://localhost:55703/Home/ValidStep1 404(未找到)

这是我的代码:

HomeController.cs

[HttpPost]
public JsonResult ValidStep1(Dictionary<string, List<string>> listUsers){
//some code
}

索引.cshtml

jQuery.post('/Home/ValidStep1', { listUsers: listUser }, function (data) {
  if (data) {
    document.location.replace("@ViewBag.nextStep");
  }
  else {
    document.location.replace("@ViewBag.errorStep");
  }
});

你有什么想法吗?

【问题讨论】:

  • 不,但它甚至没有找到方法“ValidStep1”所以......
  • 根据您设置端点路由的方式,您要查找的 url 可能需要包含控制器名称。试试看:localhost:55703/Home/ValidStep1
  • 刚刚更新.. :/
  • 通过运行 frow cmd.exe 查找端口 55703 来查看服务是否正在运行 >Netstat -a 如果您需要安全连接 HTTPS 并且您只使用 HTTP,则可能会出现错误 404。
  • 你们知道为什么它现在适用于 .ajax() 但不适用于 .post() 吗?

标签: c# jquery post razor http-status-code-404


【解决方案1】:

好的,现在它可以使用以下代码。但我不知道为什么。就像……和上面一样。

jQuery.ajax({
  type: 'POST',
  url: '@Url.Action("ValidStep1", "Home")',
  data: { listUsers: listUser },
  success: function (data) {
      document.location.replace("@ViewBag.nextStep");
  },
  error: function () {
      document.location.replace("@ViewBag.errorStep");
  }
});

【讨论】:

    猜你喜欢
    • 2016-08-06
    • 2021-10-31
    • 2017-06-14
    • 2017-09-23
    • 2021-03-11
    • 2019-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多