【发布时间】:2013-08-14 22:18:46
【问题描述】:
这是我的控制器;
public class ProductionStateController : ApiController
{
private readonly IFranchiseService _franchiseService;
public ProductionStateController(IFranchiseService franchiseService)
{
_franchiseService = franchiseService;
}
[DataContext]
public string PutProductionState(int id, FranchiseProductionStates state)
{
_franchiseService.ChangeProductionState(id, state);
var redirectToUrl = "List";
return redirectToUrl;
}
}
我的 ajax 调用;
self.selectState = function (value) {
$.ajax({
url: "/api/ProductionState",
type: 'PUT',
contentType: 'application/json',
data: "id=3&state=Pending",
success: function (data) {
alert('Load was performed.');
}
});
};
我的路线;
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
我收到404 File not found 错误。
如果我将方法替换为POST,则相同。
如果我做到GET 一切正常。
我在这里遗漏了一些东西。任何帮助将不胜感激。
【问题讨论】:
标签: asp.net-mvc-3 asp.net-mvc-4 asp.net-web-api