码迷,mamicode.com
首页 > Windows程序 > 详细

webapi ,前台json传入raw读取

时间:2015-09-14 20:54:40      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:

[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("错误异常");
}
});
});

webapi ,前台json传入raw读取

标签:

原文地址:http://www.cnblogs.com/lccnblog/p/4808031.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!