Complex type is getting null in a ApiController parameter

前端 未结 4 1231
借酒劲吻你
借酒劲吻你 2020-11-27 03:29

I don´t know why my parameter \"ParametroFiltro Filtro\" is getting null, the other parameters \"page\" and \"pageSize\" is getting OK.

public class Parametr         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 04:10

    It's also possible to access POST variables via a Newtonsoft.Json.Linq JObject.

    For example, this POST:

    $.ajax({
        type: 'POST',
        url: 'URL',
        data: { 'Note': note, 'Story': story },
        dataType: 'text',
        success: function (data) { }
    });
    

    Can be accessed in an APIController like so:

    public void Update([FromBody]JObject data)
    {
        var Note = (String)data["Note"];
        var Story = (String)data["Story"];
    }
    

提交回复
热议问题