我设法创建了一个 ApiController 从我的存储库中检索数据,并通过带有 Ajax 的 Bootgrid在我的视图中填充了一个网格。这是发送到 Api 操作的请求数据的示例,由他们的 Docs here给出(查找 POST Body Request 选项卡):
current=1&rowCount=10&sort[sender]=asc&searchPhrase=&id=b0df282a-0d67-40e5-8558-c9e93b7befed
这是一个示例网址:
http://localhost/api/SomeController?current=1&rowCount=10&sort%5BName%5D=asc&searchPhrase=&id=b0df282a-0d67-40e5-8558-c9e93b7befed
我创建了两个 Helper 类来处理我必须作为响应返回的数据,并对数据进行排序(因为它是一个数组):
public class SortData
{
public string Field { get; set; } // FIeld Name
public string Type { get; set; } // ASC or DESC
}
public class BootgridResponseData<T> where T: class
{
public int current { get; set; } // current page
public int rowCount { get; set; } // rows per page
public IEnumerable<T> rows { get; set; } // items
public int total { get; set; } // total rows for whole query
}
因此,我的操作如下:
public BootgridResponseData<SomeViewModel> Get(int current, int rowCount, List<SortData> sort, string searchPhrase, string id)
{
// get items and return a bootgrid response data with them...
}
该方法被调用并且所有参数都正确地带有数据,除了排序,它始终为空。
我应该期待什么样的参数?我也试过放object
,但无论如何它都是空的。