jquery validate always returning true

前端 未结 5 1253
北荒
北荒 2020-12-31 21:16

I am using MVC4 w/JQuery and I have a form I created using the @Ajax.BeginForm. It has required fields (set on its view model). I am trying to validate the form before it is

5条回答
  •  甜味超标
    2020-12-31 21:58

    For Googlers - This can also happen when you don't have the proper Bind Attributes in your MVC route. For example, if you post a form element with a name that's not in the Include list, you may get the error.

    // make sure the list matches your form elements. 
    public ActionResult Edit([Bind(Include = "Username,FullName,Email")] User user)
    

    Either make sure your form names match those in the Include list, or remove the Bind Attribute all together (if you don't mind sacrificing security).

提交回复
热议问题