0
@using (Ajax.BeginForm("EditParameterSet", "MRServiceHome", new AjaxOptions { UpdateTargetId = "parameterList" }))
{
           @Html.EditorFor(x => x.ControlList)
           <input type="submit" id="verifyBtn" value="Verify"/>
}

Where "EditParameterSet" is my controller method, MRServiceHome is my controller, and "parameterlist" is my div.I'm creating controls using partial view.

My controller code is

[HttpPost]
        public PartialViewResult EditParameterSet(SttModel model)
        {
        }

My question is how can i avoid call to the controller if there are any client side validation errors. I'm using my custom validation logic for the client side validation.

Dwellerincellar
  • 145
  • 1
  • 2
  • 12
  • Then make sure your custom validation logic doesn't make the POST when it encounters invalid input. If your actual question is _"How to prevent form POST using javascript?"_, then do a search for that and see for example [javascript to stop form submission](http://stackoverflow.com/questions/8664486/javascript-to-stop-form-submission). If not, please explain what exactly you're looking for, what code you currently have, what it does and why it doesn't match your expectations. The code you show is not relevant to the question. :) – CodeCaster Mar 09 '14 at 15:15
  • well,i cant disable the submit button on validation failure due to bussiness logic contraint. – Dwellerincellar Mar 09 '14 at 15:22
  • So what is your question? :) – CodeCaster Mar 09 '14 at 15:25
  • i just want to avoid call to this controller method .. sorry about my limited knowledge about mvc, an still a rookie in mvc:( – Dwellerincellar Mar 09 '14 at 15:29
  • 1
    To prevent a form POST, you need to use javascript. Again, please see [javascript to stop form submission](http://stackoverflow.com/questions/8664486/javascript-to-stop-form-submission). – CodeCaster Mar 09 '14 at 15:29

1 Answers1

0

You could intercept the submit event and then check if the form is valid:

$('#yourFormName').submit(function() {
   $(this).validate();
   if (!$(this).valid()) { return false; }
});

in other words if your submit event returns false the form will not submit. Above I am showing you how to do it with jquery unobtrusive validation but you can just plug in your custom logic and return false if the condition is not met - form is invalid.

Marko
  • 12,543
  • 10
  • 48
  • 58