Skip to content

$.ajax post JSON.stringify(para) is null #1177

@yuezhongxin

Description

@yuezhongxin

JavaScript code:

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 code:

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

The above code uses asp.net mvc 5 works, but use asp.net 5 does not work.

I modified the action of the code, it works.

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...
}

Use asp.net 5, I have to write it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions