且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MVC Ajax调用控制器方法

更新时间:2023-02-25 15:39:30

您的对象属性与操作的参数冲突

Your object properties conflict with the arguments of the action

对象属性

{
   userId : id,
   comments : $("#comment").val()
}

与动作参数

 int id, string comment

尝试更改它们以使其匹配,例如:

Try changing them to match, so for example:

public ActionResult User(int userId, string comments) { ... }

请注意,您将无法从异步请求重定向到操作.有点失败的目的.您需要在回调上进行重定向.

Please note you're not going to be able to redirect to action from an asynchronous request. It kind of defeats the purpose. You would need to redirect on a callback.