如何使用FromQuery属性获取复杂的对象? [英] How to use FromQuery Attribute get a complex object?

查看:104
本文介绍了如何使用FromQuery属性获取复杂的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用FromQueryAttribute获取复杂的对象?

How to use FromQueryAttribute get a complex object?

[HttpGet]
public IActionResult Get([FromQuery] DataGridRequest request)
{
    ...
}

像这样的DataGridRequest类:

The DataGridRequest class like this:

public class DataGridRequest
{
    public DataGridPager Pager { get; set; }

    ...
}

public class DataGridPager
{
    public int Size { get; set; }

    public int Index { get; set; }
}

如何编写uri?

推荐答案

您可以尝试这样的Get请求

You can try a Get request like this

controller?Size=1&Index=2

也尝试使用 [FromUri] 代替 [FromQuery] . [FromUri] 属性尝试按名称将对象属性绑定到查询字符串属性

Also try to use [FromUri] instead [FromQuery]. The [FromUri] attribute tries to bind the object properties to the query string properties by name

这篇关于如何使用FromQuery属性获取复杂的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆