ASP.NET MVC
ASP.NET CORE POST로 Json 데이터보내기
스티커
2019. 9. 28. 15:21
클라이언트
var result = JSON.stringify(aspNetUserActionLog); 안해주면 서버에서 null로 받는다.
* stringify 메소드는 json 객체를 String 객체로 변환
function fn_setLogDB( comment ) {
var email = userName;
var projectId = $("#hidProjectId").val();
var aspNetUserActionLog = {};
aspNetUserActionLog.Email = email;
aspNetUserActionLog.UserActioin = comment;
//data: JSON.stringify(dataJSON),
var result = JSON.stringify(aspNetUserActionLog);
$.ajax({
type: "POST",
url: "/api/userLog" ,
data: result ,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (data) {
// alert('저장성공');
},
error: function (message) {
alert(message);
}
});
}
서버측
[System.Web.Http.Route("api/userLog")]
[System.Web.Http.HttpPost]
public void SetLog([FromBody] AspNetUserActionLog aspNetUserActionLog)
{
HttpRequestMessage request = this.Request;
var content = request.Content;
}