发布JSON获取null对象

时间:2017-06-09 06:04:55

标签: jquery json post

我正在编写一个asp.net Web表单应用程序,并尝试从表单发布数据,但在我的控制器中,我发布的对象为null。

获取请求工作正常。 我已经做了很多次类似的工作,但唯一的区别是应用程序这次使用HTTPS运行,我认为这不会产生任何影响。

我的模特

enter image description here

我的jquery帖子

function AddContactClicked() {

var contactMeetings = { name: "Shafaqat Ali", completeAddress: "completeAddress" };
$.ajax({
    type: "POST",
    data: JSON.stringify(contactMeetings),
    url: "/api/contact/AddContact",
    dataType: 'json',
    contentType: 'application/json; charset=utf-8'
}).done(function (data) {
    alert(data);
}).fail(function (info) {

});
}

控制器

[Route("AddContact")]
[HttpPost]
// POST: api/Contacts
public void Post([FromBody] ContactMeeting contactMeetings)
{
}

enter image description here

Chrome开发者控制台

enter image description here

更新

这很有效。

var contactMeetings = { name: "Shafaqat Ali", completeAddress: "completeAddress" };
var jqxhr = $.post('/api/contact/AddContact', contactMeetings)
    .success(function () {
        alert("posted");
    })
    .error(function () {
        $('#message').html("Error posting the update.");
    });

0 个答案:

没有答案
相关问题