【发布时间】:2016-04-18 21:42:41
【问题描述】:
我创建了 web api,我正在使用 angularjs 使用它,并且 $http.get 正在工作,但 $http.post 没有显示错误
未找到与请求 URI 匹配的 HTTP 资源
这是我的控制器操作
[HttpPost]
public object getItem_byRetailerID(int retailerID, DateTime date)
{
string msg = null;
object listItem = new object();
try
{
mf = new milkFactoryEntities();
listItem = mf.p_item_getItem_byRetailerID(retailerID, date);
}
catch (Exception ex)
{
msg = "Error : " + ex.Message;
}
return Json(new { msg = msg, listItem = listItem });
}
WebApiConfig
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "api",
routeTemplate: "login/api/{controller}/{action}"
);
config.EnableSystemDiagnosticsTracing();
var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
}
这是我的角度控制器
var param = { retailerID: retailerID, date: $scope.ro.orderDT };
$http.post('http://localhost:60124/api/' + 'retailerOrder/getItem_byRetailerID', JSON.stringify(param)).then(function (d) {
console.log(d);
$scope.listItems = d.data.listItem;
}, function (error) {
console.log(error.data);
})
请帮忙...
【问题讨论】:
标签: jquery angularjs asp.net-mvc asp.net-web-api