博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
webapi ,前台json传入raw读取
阅读量:5097 次
发布时间:2019-06-13

本文共 1471 字,大约阅读时间需要 4 分钟。

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

转载于:https://www.cnblogs.com/lccnblog/p/4808031.html

你可能感兴趣的文章
苹果IOS系统SVN命令 同样适用于linux系统
查看>>
原型模式登记形式
查看>>
享元模式
查看>>
转:RMAN-06023 : no backup or copy of datafile found to restore 说明
查看>>
pcl库的配置
查看>>
FastDFS 分布式文件存储目录
查看>>
TmemoryStream ,bety[], TByteDynArray文件转化函数小结
查看>>
第一个只出现一次的字符
查看>>
235. Lowest Common Ancestor of a Binary Search Tree
查看>>
MySQL 备份恢复(导入导出)单个 innodb表
查看>>
语义分割的简单指南 A Simple Guide to Semantic Segmentation
查看>>
Javascript正则表达式
查看>>
常见笔记本进入bios方法
查看>>
左右滚动的东西
查看>>
Dwz手册的补充说明和常见问题
查看>>
Mybatis 传入List类型参数,报错:There is no getter for property named '__frch_item_0' in
查看>>
不可轻视复制构造函数
查看>>
Mysql高阶
查看>>
vb.net向Excel中写入值
查看>>
builder模式-积木系列
查看>>