WebAPI model binding complex object to [FromUri] sent via query string

I have read a lot of questions about why model binding is not working, but my question is actually the opposite. I'm curious: why does the binding of the model to a complex object happen in the next GET action, even if there is no data in the query string that matches any of the object's properties?

Route configuration:

configuration.Routes.MapHttpRoute(
    "Items- Get By Client ID",
    "clients/{id}/items",
    new
    {
        controller = "Item",
        action = "GetByClientId",
        constraints = new { id = @"\d+" }
    }
);

      

Request parameters class:

public class QueryOptions
{
    public int Skip { get; set; }
    public int Take { get; set; }
}

      

Act:

[HttpGet]
public HttpResponseMessage GetByClientId(int id, [FromUri] QueryOptions queryOptions = null)
{
    // Operations
}

      

example GET

use case:/api/clients/1234/items

This results in an action in which it occurs // Operations

that has a non-null object instance for queryOptions

, with default values ​​for properties. In this case, Skip

and Take

0

.

I would expect that queryOptions

would be null

, unless the property names are not used in the query string, for example: /api/clients/1234/items?skip=0&take=5

. Can anyone explain this behavior?

+3
c # asp.net-web-api model-binding


source to share


No one has answered this question yet

Check out similar questions:

64
Simple Web Api Publishing
4
ASP.NET Web API Model Binding an Unclassified List of Complex Objects
3
Binding a custom WebAPI model of a complex abstract object
2
ASP.NET MVC - how to "unbind" a model to convert a C # model back to query string representation
1
Interacting with a nested Query model
1
WebApi - UrlHelper.Route for GET with object parameter [FromUri]
1
Asp.Net WebApi model binding model with null datetime
1
Property binding in a comprehensive Web API model
0
ASP.NET WebAPI2 Global custom model binding for [FromUri] to handle 'null' in requests uri "someMethod? SomeId = null"
0
MVC4 model substitution with two complex models



All Articles
Loading...
X
Show
Funny
Dev
Pics