0

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.

2
  • does machines installed exactly same version of dotnet(including patch number)? Commented Oct 20, 2021 at 18:59
  • yes, all the same Commented Oct 20, 2021 at 19:53

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.