在ASP.Net MVC中的相同的观点分离两种形式 [英] Separating two forms in the same view in ASP.Net MVC

查看:99
本文介绍了在ASP.Net MVC中的相同的观点分离两种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经合并了创建账户视图,并在同一视图查看日志中。因此,这两种形式的观点,但他们得到的混合时,我提交。如果我尝试登录,还有就是显示一个错误:

I've merged the create account view and the log in view in the same view. So it's a view with two forms, but they get mixed when I submit. If I try to log in and there's an error that is displayed with:

Html.ValidationSummary()

这两种形式得到的错误。我开始重命名为loginPassword,createPassword领域,因为否则的话,当我提出和密码丢失,它被标记为失踪两侧。

both forms get the error. And I started to rename fields to loginPassword, createPassword, because otherwise when I submit and the password is missing, it's marked as missing on both side.

什么是这两种形式分开的方式,使他们能够在同一视图/页面上indenpendently工作?

What would be the way to separate these two forms so they can work indenpendently on the same view/page?

推荐答案

我不得不处理同样的问题。我发现,没有办法单独使用内置的ValidationSummary()的验证消息。这里有两个建议:

I had to deal with the same problem. I found that there is no way to separate the validation messages using the built in ValidationSummary(). Here are two suggestions:


  1. 保留在可能适用于这两种形式的区域验证摘要位置。例如,如果登录和注册表格并排放置两种形式上方居中的div验证摘要。我发现这种风格在马洛登录页面的例子。

  2. 在适当的控制器a​​ction方法,添加一些东西到ViewData的指示哪些动作被调用。在视图会有一个表单的提交的ValidationSummary,但每个将呈现有条件根据您添加到ViewData的东西。

无论哪种方式,表单字段应该唯一命名的。

Either way the form fields should be uniquely named.

我的解决方案#1去,因为我很满意,我能得到它的样子。但是如果你需要验证摘要根据已提交该表格出现在两个不同的位置,去与#2。

I went with solution #1 because I was satisfied with the way I was able to get it to look. But if you need the validation summary to appear in two different locations depending on which form was submitted, go with #2.

这篇关于在ASP.Net MVC中的相同的观点分离两种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆