Fis*_*eon 1 .net c# asp.net-mvc jquery asp.net-web-api
我在 jQuery 中有这个函数
var uri = "api/queries";
function test(){
var params = {
origin: $('#depair').val(),
destination: $('#destair').val(),
departure_date: $('#depdate').val(),
currency: $('#currency').val(),
}
$.getJSON(uri, params)
.done(function (data) {
console.log(data);
});
}
Run Code Online (Sandbox Code Playgroud)
它将请求发送到此Controller:
public class QueriesController : ApiController
{
[HttpGet]
public string GetInfo()
{
return "blah";
}
}
Run Code Online (Sandbox Code Playgroud)
所以,请求看起来像这样
http://localhost:55934/api/queries?origin=&destination=&departure_date=¤cy=
如何从控制器GetInfo方法内部访问请求的参数?
您可以将它们作为参数包含到您的函数中。
[HttpGet]
public string GetInfo(string origin, string destination, string departure_date, string currency)
{
return "blah";
}
Run Code Online (Sandbox Code Playgroud)