Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Closed Issue: ModelBinder errors (parse) for required action parameters result in the action not getting executed. [942]

$
0
0
```
public class CustomersController : ApiController
{
public Customer GetCustomer(int key)
{
return null;
}
}
```

Use the url http://localhost/MyTypes/2886753098675309

This should fail to parse as 2886753098675309 is too big for an int.

Expectation: The controller action gets invoked, with model state errors - or at least a better error message that contains the model state errors.

Result:

```
{
"Message": "The request is invalid.",
"MessageDetail": "The parameters dictionary contains a null entry for parameter 'key' of non-nullable type 'System.Int32' for method 'RuntimeTests.Customer GetCustomer(Int32)' in 'RuntimeTests.CustomersController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."
}
```

See http://aspnetwebstack.codeplex.com/workitem/936 for how this makes OData scenarios harder.
Comments: Because the "key" parameter is a regular int, it is a ValueType, which means that it must have a valid value in order to be called. To get the action to be called you can use a nullable int ("int?") and then the action should be dispatched and ModelState will contain the error.

Viewing all articles
Browse latest Browse all 7215

Trending Articles