JavaScript 代码:

var para = {};
para.id = $("#ad-text-id").val();
para.title = $("#ad-text-title").val().trim();
para.link = $("#ad-text-link").val().trim();
$.ajax({
    url: '/ajax/AdText/SaveAdText',
    data: JSON.stringify(para),
    type: 'post',
    dataType: 'json',
    contentType: 'application/json; charset=utf-8',
    cache: false,
    success: function (data) {
    },
    error: function (xhr) {
    }
});

Action 代码:

[HttpPost]
public async Task<JsonResult> SaveAdText(int id, string title, string link)
{
    //id, title, link para is null...
}

使用 ASP.NET 5,Action 获取到的参数都为 null,但使用之前的 ASP.NET MVC 5 是可以的,需要更改下代码:

public class Model
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string Link { get; set; }
}

[HttpPost]
public async Task<JsonResult> SaveAdText([FromBody]Model model)
{
    //model.Id, model.Title, model.Link is not null...
}

ASP.NET 5 POST Model,需要使用 FromBody。

参考:$.ajax post JSON.stringify(para) is null

相关文章:

  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-12-11
  • 2021-12-03
  • 2021-11-23
  • 2021-06-06
猜你喜欢
  • 2021-12-02
  • 2021-08-05
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
相关资源
相似解决方案