Answer the question
In order to leave comments, you need to log in
How to cast model field type to int in asp.net?
There is a model that arrives in the request body in json format.
Some providers send the field as an int, others as a string (but the string is also a number, that is, parsing will be 100% successful)
You can somehow specify in asp.net that the field should be converted to int if it came as a string, or is it In any case, you need to write your own ModelBinder?
Answer the question
In order to leave comments, you need to log in
If you use asp net core with Newtonsoft json, then by default such logic works there (I tried to turn it off myself, but I couldn’t)
There seems to be a separate option in System.Text.Json to enable / disable such logic, but this should be looked at in the documentation .
Well, you can always write your own converter
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question