Javascript:
$.post("/DataAPI/messageProcessor", { query: "Hello World!" }, function (data) {
Handle(data);
}
});
Controller :
[System.Web.Http.AcceptVerbs("Post")]
[System.Web.Http.ActionName("messageProcessor")]
public ResponseModel messageProcessor(string query)
{
ResponseModel model=DoStuff(query);
return model;
}
如何从 Controller 访问查询
。它总是以 query == null
形式到达。也有可用的 Request
对象,但我不确定如何导航其成员以到达我的“Hellow World!”
。
最佳答案
您需要从客户端传递名称-值对:
$.post("/DataAPI/messageProcessor"
, { query: "Hello World!" }
, function (data) {} );
检查jQuery.Post了解更多详情。
关于c# - 如何在 Controller 中访问 POST 请求的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13920571/