ASP.NET MVC 向导和 xVal 验证

发布于 2024-08-19 23:10:49 字数 364 浏览 2 评论 0原文

我正在 ASP.NET MVC 中构建一个向导式应用程序,想知道您对我当前的方法是否有任何反馈。

向导的每个步骤都是由 DIV 包装的部分视图(用户控件)。所有 DIV 都显示在同一视图 (Create.aspx) 上。然后,我使用 jQuery 转到下一步或上一步 - 换句话说,隐藏或显示特定的 DIV。

它工作得很好,但现在我需要实施验证。因此,我已经实现了 xVal,但目前仅在向导的最后一步提交表单时才会进行验证。

相反,我想在执行过程中验证我的模型,这样如果步骤 1 中的输入无效,我就无法继续执行步骤 2。

基本上,当我要切换到下一步时,我想调用 xVal 验证过程。

关于如何去做有什么想法吗?

谢谢。

I'm building a wizard-style application in ASP.NET MVC and is wondering if you have any feedback on my current approach.

Each step of the wizard is a partial view (user control) wrapped by a DIV. All DIV's are shown on the same view (Create.aspx). I then use jQuery to go to next or previous step - in other words hide or show a specific DIV.

It works great, but now I need to implement validation. So I've implemented xVal, but currently the validation only occurs when the form is submitted on the final step of the wizard.

Instead I would like to validate my model as I go, so that I cannot go forward to step 2 if the input in step 1 was invalid.

Basicly I'd like to invoke the xVal validation process, when I'm about to switch to the next step.

Any thoughts on how to go about doing that?

Thank you.

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

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

发布评论

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

评论(1

农村范ル 2024-08-26 23:10:49

xVal 在支持下构建 jQuery 的 验证插件 就在门口。您应该能够在需要时使用插件的 API 来调用 Validate() 和 Valid() 方法。

例如,在每次单击“移至下一步”按钮时,您可以调用 valid() 在当前步骤中的每个输入上,查看是否应该继续。

$("#myform").validate();
$("a.nextstep").click(function() {
  if (!$("#input1").valid());
  return false;
});

xVal is built with support for jQuery's Validation plugin right out of the gate. You should be able to work with the plug-in's API to call the Validate() and Valid() methods whenever you need to.

For example, on each "move to next step" button click, you could call valid() on each input in the current step, to see if you should proceed or not.

$("#myform").validate();
$("a.nextstep").click(function() {
  if (!$("#input1").valid());
  return false;
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文