如何使用jQuery Ajax将对象列表传递到MVC控制器方法?

时间:2017-06-29 13:21:15

标签: javascript c# asp.net-apicontroller

这是我的API控制器。 customfiltervalues为null:

[HttpPost]
[Route("api/ajaxapi/customfilters")]
public List<CustomCaseValues> CustomFilters(List<CustomFilterValues> customfiltervalues)
{

这是我的数据:

    var customfiltervalues =[
        {
            TableName: $('#tableOneTableName').val(),
            ColumnName: $('#tableOneColumnName').val(),
            Condition: $('#tableOneCondition').val(),
            TextBox: $('#tableOneTextBox').val(),
            Operator: $('#tableOneOperator').val()
        },
        {
            TableName: $('#tableTwoTableName').val(),
            ColumnName: $('#tableTwoColumnName').val(),
            Condition: $('#tableTwoCondition').val(),
            TextBox: $('#tableTwoTextBox').val(),
            Operator: $('#tableTwoOperator').val()
        },
        {
            TableName: $('#tableThreeTableName').val(),
            ColumnName: $('#tableThreeColumnName').val(),
            Condition: $('#tableThreeCondition').val(),
            TextBox: $('#tableThreeTextBox').val(),
            Operator: $('#tableThreeOperator').val()
        }
    ];

这是我的Ajax电话:

    $.ajax({
            traditional: true,
            type: "POST",
            url: domainName + "api/ajaxapi/customfilters",
            data: JSON.stringify(customfiltervalues),
            beforeSend: function (request) {
                request.setRequestHeader("Authorization", getCookie("Token"));
            },
            success: function (response) {}

这是我的班级:

public class CustomFilterValues
{
    public string TableName { get; set; }

    public string ColumnName { get; set; }

    public string Condition { get; set; }

    public string TextBox { get; set; }

    public string Operator { get; set; }
}

0 个答案:

没有答案