“返回”验证的逐步问题按钮

发布于 2024-10-08 01:12:22 字数 198 浏览 0 评论 0原文

我有一个 3 步骤表单,我在具有 DataAnnotation 的 ViewModel 上绑定每个步骤。一切工作正常,除了当我单击“上一个”按钮时,会调用验证,如果缺少值,用户必须填写所有必填字段。如果我使用操作链接,那么数据将不会被保留。我在这里寻找的是一种无需调用验证即可保存值的方法。我也考虑使用 cookie,但我不认为这是最好的方法。

有什么想法或建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若言繁花未落 2024-10-15 01:12:22

我为向导页面的每个步骤使用单独的模型。我还确保之前的单击不会触发 ModelState.IsValid,这会触发验证检查。

我使用 SQL Server 中存储的会话状态来存储每个步骤的结果。您也可以使用隐藏变量,但我不喜欢这个解决方案。

如果您需要更多详细信息或显示一些代码供我们查看,请添加评论。

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.

好久不见√ 2024-10-15 01:12:22

好吧,经过大量搜索后,我找到了一个解决方案,可以使用向导(例如带有上一个和下一个按钮的多个表单),不会从数据注释和 MicrosoftMvcValidation.js 调用客户端验证。我发现这篇文章: jQuery 验证插件:禁用指定提交的验证按钮女巫只需向提交按钮添加一个类,但它对我不起作用,所以我再看一遍,发现了这个:http://forums.asp.net/p/1622628/4165648.aspx 女巫有一个在 javascript 中为我工作的解决方案: document.getElementById("someButton ").disableValidation = true; 我更喜欢 jQuery 解决方案,这样我就可以用按钮的类属性做一些事情,但它今天就可以工作了,我在这上面花了太多时间。

希望它可以帮助其他尝试在 MVC2 中执行“取消”按钮或类似向导的表单并希望将表单发布到控制器的人,以便他需要清除验证。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文