Model is null when form submitted

人走茶凉 提交于 2019-11-28 09:06:31
webdeveloper

It's naming conflict and binder trying to bind your File property to FileViewModel object with file name, that's why you get null. POST names are case-insensitive.

Change:

public ActionResult Create(FileViewModel file)

To:

public ActionResult Create(FileViewModel model)

or to any other name

This solved my issue as well. It was a name that I was using that was similar to the model, which was similar to the variable I assigned the posted model too. once I sorted out the field name all worked as expected.

Of course the error was not helpful in pointing this out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!