How to Use Fromquery Attribute Get a Complex Object?

How to Use Fromquery Attribute Get a Complex Object?

How to use FromQueryAttribute get a complex object?

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

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

How to write the uri?

4

2 Answers

You can try a Get request like this

controller?Size=1&Index=2

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

3

Do this to set data for subobjects using [FromQuery]:

controller?Pager.Size=1&Pager.Index=2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.