首页 新闻 会员 周边

.net core post请求控制器

0
悬赏园豆:5 [待解决问题]

前端:
this.$http.post('/Login/Register', this.user, {
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
})
.then(function (response) {
var statu = response.Statu;
if (statu == "ok")
window.location.href = "../Home/Home.cshtml"
}, function (response) {
})

后台
[HttpPost("/Login/Register")]
[ExceptionFilter]
public JsonResult Register([FromBody]Domain.User user)
{
int userId = UserService.InsertSingle(user);
return new JsonResult(new { Statu = "ok" });
}
我f12看了请求报文request有user值,但是后台的一直为null

灬丶的主页 灬丶 | 初学一级 | 园豆:2
提问于:2018-12-19 20:59
< >
分享
所有回答(2)
0

加上 JSON.stringify 试试

this.$http.post('/Login/Register', JSON.stringify(this.user), {
}
dudu | 园豆:30994 (高人七级) | 2018-12-19 21:13

还是为null

支持(0) 反对(0) 灬丶 | 园豆:2 (初学一级) | 2018-12-19 21:19

@灬丶: 改一下 angular post 请求的 headers 试试

let headers = new HttpHeaders(); 
headers.set("Content-Type", "application/json");
this.$http.post('/Login/Register', JSON.stringify(this.user), { headers:  headers })
支持(0) 反对(0) dudu | 园豆:30994 (高人七级) | 2018-12-19 21:30
0

this.$http.post('../Action/Admin.ashx', { datatype: 'AddWord', clientJson: JSON.stringify(this.addUserModalData) }, { emulateJSON: true }).then(function (data) {

})

DNLi | 园豆:316 (菜鸟二级) | 2018-12-20 08:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册