【问题标题】:Why does jquery load not work when mvc httppost is defined?为什么定义mvc httppost时jquery加载不起作用?
【发布时间】:2012-01-19 15:05:02
【问题描述】:

以下配置有效 - 它将编辑视图加载到 div 中:

jQuery:

$("#mydiv").load(
    "/Riders/Edit",
    { riderId: 123 },
    function (data) { }
);

RidersController:

Function Edit(ByVal riderId As Integer) As ActionResult
    Return View(_db.Riders.Single(Function(x) x.rider_id = riderId))
End Function

但是当我将 HttpPost 添加到控制器进行编辑时,我得到一个错误:

<HttpPost()>
Function Edit(ByVal model As Rider) As ActionResult
   'code...
End Function

错误:

POST http://localhost:4693/Riders/Edit 500 (Internal Server Error)

现在为什么我会在加载时收到 POST 错误?我确定我只是在我的设置中遗漏了一些东西,但我还没有看到它。

【问题讨论】:

  • @musefan 是的,正如您所描述的,这两个操作都在控制器中。

标签: jquery asp.net-mvc http-post


【解决方案1】:

您正在使用 GET 方法传递参数,因此如果您将其指定为 POST,它永远不会找到您的控制器操作。从此链接:http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/

如果参数作为对象(而不是字符串)传递,它们是 在 POST 方法中传递给远程 url。

这将是您的解决方案。

【讨论】:

  • 宾果游戏!我知道这很简单。我很确定我以前也遇到过。这个链接很有帮助,谢谢!
猜你喜欢
  • 1970-01-01
  • 2023-04-03
  • 2015-01-28
  • 2020-12-10
  • 2014-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-02
相关资源
最近更新 更多