前端:
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
加上 JSON.stringify 试试
this.$http.post('/Login/Register', JSON.stringify(this.user), {
}
还是为null
@灬丶: 改一下 angular post 请求的 headers 试试
let headers = new HttpHeaders();
headers.set("Content-Type", "application/json");
this.$http.post('/Login/Register', JSON.stringify(this.user), { headers: headers })
this.$http.post('../Action/Admin.ashx', { datatype: 'AddWord', clientJson: JSON.stringify(this.addUserModalData) }, { emulateJSON: true }).then(function (data) {
})