0

The following JQuery line lets me get passed validation but the serverside raises an error.

$(document).ready(function () {

    $("#save").click(function () {
        $("#WizForm").validate({
            onsubmit: false
        });
    });

How do I set the ModelState to be successful and allow me to continue to save my data as a draft entry? Right now I get the following error. Should I remove the rules? Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

1
  • Maybe you should have different controller actions for creating a draft and saving the finalized object... Commented Jun 27, 2011 at 16:59

1 Answer 1

1

As Andrew Whitaker suggested, you should have two different controller actions, one for drafts (forms which fail validation), and one for final forms which pass validation. In addition, you should create an unvalidated model for your draft object.

Your client side script should be similar to the following:

$(document).ready(function() {
  $("#save").click(function () {
    if ($("wizForm").validate().form()) {
      // call controller action SaveFinal
    }
    else {
      // call controller action SaveDraft
    }
  }
}

Then, create a model without validation, and use this model in your SaveDraft controller action.

public ActionResult SaveDraft(UnvalidatedModel draft)
{
   // step through each field, and save only valid fields
}

counsellorben

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.