ASP.NET MVC Model Binder returns null object

后端 未结 1 408
再見小時候
再見小時候 2020-12-16 01:14

I am having a problem where everytime I post a form back to the [HttpPost] version of my controller action, the ModelBinder returns a null object. I can\'t work

1条回答
  •  有刺的猬
    2020-12-16 02:07

    The problem is that there is a name collision between the property named Model in the class DeviceModel and the variable named model in the Create action. The name collision causes the DefaultModelBinder to fail, since it tries to bind the Model property to the DeviceModel class.

    Change the name of the variable in the Create action to deviceModel and it will bind correctly.

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