I have a web api controller with HttpGet method inside.
The controller sets it's route in a parametrized RouteAttribute (catalogId doesn't have :int or :long rules by an intention).
The controller's method accepts RequestModel model with the same named property inside.
[Route("api/{catalogId}")]
class MyController : Controller
{
[HttpGet]
public IActionResult MyMethod([FromRoute]RequestModel model)
{
return Ok(model?.CatalogId ?? "Model.Property is not binded!");
}
}
public class RequestModel
{
[FromRoute]
public long? CatalogId { get; set; }
}
I tested this method by passing valid numbers (e.g. 123, 456), and it worked well:
http://localhost:5000/api/123
I also tried to pass numbers with leading or trailing whitespaces and it worked too (e.g. "123%20", "%20456"):
http://localhost:5000/api/123%20
As I investigated later, long.Parse method, that is probably used in the defaul model binder, accepts such input according to the default NumberStyle options.
But on some other machines this binding is not done: the property CatalogId is null. It seems for me, there might be a reason for different parsing rules. I tried to set Thread.CurrentCultue to Invariant one, I tried to apply RequestLocalizationOptions, but it didn't help.
What else can possibly influence on the default Model Binding behaviour? Thanks in advance.