3

In MVC4,.net 4.6.1 and VS 2015, I write a simple MVC app to pass a short type value from view to controller like this

public bool GetTheValue (short req_division)
{ return req_division == -1 ;}

The weird thing is when I pass -1 to req_division from my view, the result returned false. I don't know why is it happened. Can anyone explain it for me. Thank you very much !

TranQ
  • 139
  • 7

1 Answers1

12

Besides the possible typo in your code, I found something strange in the evaluation that the Debug View does. See this code:

The debugger says it is false, yet the code evaluates to true. Maybe you have hit a type conversion issue in the debugger. When changing the int to a short, the debugger thinks i == j evaluates to true after all.

Patrick Hofman
  • 143,714
  • 19
  • 222
  • 294