Asp.net core model doesn't bind from form

后端 未结 10 882
没有蜡笔的小新
没有蜡笔的小新 2021-02-02 13:54

I catch post request from 3rd-side static page (generated by Adobe Muse) and handle it with MVC action.

10条回答
  •  野性不改
    2021-02-02 14:24

    ASP.Net Core 3.1

    In my case, I was using a complex model (a model that contains other models, like a shared model) posted by Ajax, so the inputs in the view were automatically named like this "ChildModel.PropertyName" (see code)

       [HttpPost]
       [ValidateAntiForgeryToken] // ("AUVM.PropertyName")
       public async Task AddUser([FromForm]AUVM aUVM) //Parameter name must match the first part of the input name in order to bind
       {
    
       }
    
       [HttpPost]
       [ValidateAntiForgeryToken]
       public async Task AddUser([FromForm]AUVM someUniqueName) //This is wrong and won't bind
       {
    
       }
    

提交回复
热议问题