Does the name of parameter have to be model?

后端 未结 1 2041
暗喜
暗喜 2020-12-02 02:31

Hit a strange issue where my model is not binding and shows up on the controller as null.

I have a form doing a httppost. My breakpoint in the controller is hit and

相关标签:
1条回答
  • 2020-12-02 03:08

    Your problem is that you model contains a property named Message and you also have a parameter named message The DefaultModelBinder reads the form values which will include message = "someTextValue" and searches for model properties that have the name message. It finds the one in you model and sets it value (all OK so far) but then it finds another one (your parameter) and tries to set the value of a complex object string value (in effect ContactMessage message = "someTextValue";) which fails so the model becomes null

    0 讨论(0)
提交回复
热议问题