【发布时间】:2018-02-06 05:36:53
【问题描述】:
好的,我相信我已经接近完成这项工作,但似乎无法识别我的 WebAPI 控制器,除非我在 URI 中传递参数。
我有... 像这样使用 $resource 的 Angular...
var savePromise = myService.common.SaveData.save({},{ ID: saveObj.ID, Year: saveObj.Year, typeID: saveObj.TypeID, ObjectList: JSON.stringify(saveCollection) }).$promise;
收集 URL 并通过调用 WebAPI 传递此数据的服务...
保存数据:$resource(myURL, {})
WebAPI 控制器...
public class ObjectsSaveController : ApiController
{
[System.Web.Http.HttpPost]
public HttpResponseMessage POST([FromBody] int ID, int Year,
int typeID, string ObjectList) {
Request URL:myURL/api/ObjectsSave
Request Method:POST
Status Code:404 Not Found
Remote Address:[::1]:8081
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Content-Length:791
Content-Type:application/json; charset=utf-8
Date:Mon, 28 Aug 2017 21:11:09 GMT
Expires:-1
Persistent-Auth:true
Pragma:no-cache
Server:Microsoft-IIS/8.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
Request Headers
view source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:210
Content-Type:application/json;charset=UTF-8
Host:localhost:8081
Origin:http://localhost:8081
Pragma:no-cache
Referer:http://localhost:8081/myURL/
User-Agent:Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36
Request Payload
view source
{ID: 211313, Year: 2017, typeID: 7,…}
cropYear
:
2017
ID
:
211313
ObjectList
:
"[{"ID":-1,"Name":"","geoJSONShape":"{\"type\":\"Point\",\"coordinates\":
[-99.35464723335105,41.54277522419835]}"}]"
typeID
:
7
Name
如果我不在查询字符串中传递值,则找不到 ApiController。
感谢任何帮助!
【问题讨论】:
标签: c# jquery angularjs asp.net-web-api asp.net-apicontroller