Questpond Question and Answer

Why is my ASP.NET MVC data annotation validation is not working?

Ahtesham
13th Jul, 2017

Answer (2)

  • name 

    message Your Answer is Under Moderation

  • Imran 

    Data annotation validation will not fire when you use model binder as you are creating the objects manually using new keyword. Only and only if the objects come autommapped , i mean get automatically filled in the MVC action method input parameter then only ModelState validation will execute. For firing validation model binder code you need to manually invoke the validation. I would suggest you to watch this C# data annotation which explains how to use data annotation with simple C# video https://www.youtube.com/watch?v=Gft64NdIx3k So in the action method you need to invoke the "tryValidate" method and perform validations. Thanks

    13th Jul, 2017 Delete

Answer Now