找不到asp.net web api 2属性路由

时间:2014-01-29 00:44:51

标签: asp.net asp.net-web-api

我在名为Recruiting的API控制器中有这条路线:

 ResponseType(typeof (int))]
 [Route("Recruiting/setprimary/")]
 public async Task<IHttpActionResult> PutUpdatePrimary(string userId, string orgId)
 {
     return Ok();
 }

我试图像这样通过ajax点击这个路由:

 self.updatePrimary = function () {
    var orgKey = self.selectedOrgKey();
    alert(orgKey);
    $.ajax({
        type: "PUT",
        contentType: "application/json; charset=utf-8",
        url: "/Recruiting/setprimary/" + "?userId=" + userId + "&?orgId=" + orgKey,
        data: null,
        dataType: "json",
        success: function (data) {
            bootbox.alert('Changes saved successfully.');
        },
        error: function (err) {
            bootbox.alert('An error occured while trying to set primary organisation. Please try again :/');
        }
    });
    return true;
};

提琴手说它无法找到路线。我有什么不对吗?

1 个答案:

答案 0 :(得分:5)

您的请求网址中似乎有拼写错误:而不是"&?orgId=" ..它应该是"&orgId="