0

Im facing problem when trying to apply data annotation. In my case im passing FormCollection in controller

[HttpPost]         
public ActionResult Create(string Button, FormCollection collection)
{
if (ModelState.IsValid)
      {
      }
else
      {
      }
}

and in ModelState.IsValid condition always have true value. Although i have left some blank fields in View. Also EnableClientValidation() is also applied in View for client side validation but its not working. what may be the problem

1 Answer 1

1

Your view must be strongly typed, and the parameters of your Create function must contain an object to hold your Model, not a generic FormCollection. So if you have a model of name MyClass that you have annotated, then you should have that as the parameter. Otherwise, how will the model binder know what class should it check your form against?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.