[ActionName("CreateEmployeeTrackRecord")]
public HttpResponseMessage PostCreateEmployeeTrackRecord([FromBody]Object json) { try { var jInfo = SerializeJsonToDynamic(json.ToString()); int userId = Convert.ToInt32(jInfo.UserId.Value); int factoryId = Convert.ToInt32(jInfo.FactoryId.Value); DateTime signInTime = Convert.ToDateTime(jInfo.SignInTime.Value); DateTime signOutTime = Convert.ToDateTime(jInfo.SignOutTime.Value); string trackPoints = jInfo.TrackPoints.Value; var model = new TrackRecord { UserId = userId, FactoryId = factoryId, SignInTime = signInTime, SignOutTime = signOutTime, TrackPoints = trackPoints }; //ApiService.SaveTrackRecord(model); return ToJson(model.ID > 0 ? new ResponseMsg { Msg = "本次轨迹已保存!" } : new ResponseMsg { Status = ResponseStatus.Fail, Msg = "轨迹保存失败!" }); } catch (Exception) { return ToJson(new ResponseMsg { Status = ResponseStatus.Fail, Msg = "PostCreateTrackRecord:轨迹保存失败!" }); } } $('#submit').on('click', function () { var json = { "UserId": 7, "FactoryId": 1, "SignInTime": "2015-9-14 11:11:20", "SignOutTime": "2015-9-14 18:11:20", "TrackPoints": "[[116.301934, 39.977552, \"2015-8-9 13:10:11\"], [116.508328, 39.919141, \"2015-8-9 14:10:88\"]]" }; $.ajax({ type: "Post", contentType: 'application/json', url: "http://localhost:4338/api/webapi/CreateEmployeeTrackRecord", data: JSON.stringify(json), success: function (data) {}, error: function () { alert("错误异常"); } }); });