ModelState.IsValid does not exclude required property

后端 未结 7 1349
猫巷女王i
猫巷女王i 2020-12-06 12:22

Im trying to exclude a required property(Password) so the modelstate dont validate that property, but for some reason it still validate even when i try to exclude it.

<
7条回答
  •  余生分开走
    2020-12-06 12:54

    Seems like I'm replying too late, but I also faced the same problem.

    Check your ModelState.Keys collection. Keys might be in the form of modelObjectName.Password and same for rest of model properties.

    So in this case ModelState.Remove("Password") will not work. You should try ModelState.Remove("modelObjectName.Password")

    Hope this resolve someone's issue :)

提交回复
热议问题