Model is null when form submitted

后端 未结 2 1718
忘掉有多难
忘掉有多难 2020-12-05 23:56

When I hit submit, the file parameter is null.

public ActionResult Create()
{
  return View(new FileViewModel());
}

[HttpPost]    
[InitializeB         


        
相关标签:
2条回答
  • 2020-12-06 00:23

    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.

    0 讨论(0)
  • 2020-12-06 00:24

    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

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