step by step problem with validation on “back” button

坚强是说给别人听的谎言 提交于 2020-01-02 20:03:27

问题


I have a 3 steps forms where I bind for each step on a ViewModel that has DataAnnotation. Everything works fine except that when I click on my "previous" button, the validation gets called and, if there's missing values, the user has to fill all required fields. If I go with an action link, then the data won't be persisted. What I'm looking for here is a way to save my values without calling the validation. I also consider using cookies but I don't think that it's the best way of doing it.

Any ideas or suggestions?


回答1:


I use separate models for each step of my wizard pages. I also make sure that the previous clicks do not hit ModelState.IsValid which is what triggers the validation check.

I store the results of each step using session state stored in SQL Server. You can also use hidden variables but I didn't like that solution.

Add a comment if you need more detail or show some code for us to see.




回答2:


Ok after lots of searching I found out a solution for having a Wizard like multiple forms with previous and next buttons that won't call the client validation from Data Annotation and MicrosoftMvcValidation.js. I found this post : jQuery Validation plugin: disable validation for specified submit buttons witch simply add a class to the submit button but it was not working for me so I look again and found this one : http://forums.asp.net/p/1622628/4165648.aspx witch has a solution working for me in javascript : document.getElementById("someButton").disableValidation = true; I would prefer a jQuery solution so I could do something with the class attribute of my buttons but it's working for today and I've spent too mutch time on this.

Hope it helps some else who's trying to do a "Cancel" button or a Wizard like forms in MVC2 and want's to post the form to the controller so he needs to clear the validation.



来源:https://stackoverflow.com/questions/4430718/step-by-step-problem-with-validation-on-back-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!