I have a field called ACTIVITY_NAME which I have defined as such:
[Required(AllowEmptyStrings = false, ErrorMessage = "Acitivity Name is Required.")]
[StringLength(255)]
public string ACTIVITY_NAME { get; set; }
I setup my textbox to render it front-end like this:
@Html.TextBoxFor(m => m.EditActivity.ACTIVITY_NAME, new { @id = "ActivityName", @class = "width400", placeholder = Localization.ActivityName })
@Html.ValidationMessageFor(m => m.EditActivity.ACTIVITY_NAME)
When the form is submited, the following JS handler is fired:
$('#AddTaskActivity').click(function (evt) {
$('#activityModal').modal('hide');
evt.preventDefault();
var formData = $('#ActivityForm').serialize();
CreateActivity(formData);
});
So basically, this would prevent the default handler, and the validation would not fire. I didn't write this code, but I would like to add validation. How do I force fire the validation in the handler before it post to server?