如何将多个参数传递给ASP.NET webAPI控制器操作? [解决了] [英] How do I pass multiple parameters to an ASP.NET webAPI controller action? [SOLVED]
问题描述
永远不会调用带有两个参数的控制器操作。任何人都可以看到我做错了吗?
URL:/ api / JobTitle / 1/55(参数为1和55.)
ROUTE:
My controller action with two parameters is never called. Can anyone see what I'm doing wrong?
URL: /api/JobTitle/1/55 (The arguments are 1 and 55.)
ROUTE:
config.Routes.MapHttpRoute(
name: "With2Ids",
routeTemplate: "api/{controller}/{oldDescription}/{newDescription}"
);
(参数是oldDescription和newDescription。)
控制器:
(The parameters are oldDescription and newDescription.)
CONTROLLER:
[HttpPost]
public HttpResponseMessage UpdateJobTitle(string oldDescription, string newDescription)
{...
(参数与路线中的参数相匹配。)
CALL FROM VIEW:
(The parameters match those in the route.)
CALL FROM VIEW:
$.ajax({
url: updateUrl,
type: 'POST',
success: function (result) {
window.location = "/Views/index.html";
}
});
=========================
我添加了一个带有两个参数的自定义路由,其名称与controller-action参数相同。但它永远不会被称为。知道为什么吗?谢谢!
=========================
I've added a custom route with two parameters with the same names as the controller-action parameters. But it never gets called. Any idea why? Thanks!
推荐答案
.ajax({
url:updateUrl,
type:' POST',
成功:函数(结果){
window.location = / Views / index.html;
}
});
.ajax({ url: updateUrl, type: 'POST', success: function (result) { window.location = "/Views/index.html"; } });
=========================
我添加了一个带有两个参数的自定义路由,其名称与controller-action参数相同。但它永远不会被称为。知道为什么吗?谢谢!
=========================
I've added a custom route with two parameters with the same names as the controller-action parameters. But it never gets called. Any idea why? Thanks!
我失踪了:
这篇关于如何将多个参数传递给ASP.NET webAPI控制器操作? [解决了]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!