ASP.NET MVC 2:传递模型,防止在第二页上进行验证
这是我的设置:
模型 =>视图1 =>验证模型
模型=>视图2 =>我需要忽略验证并仅从
Model => 传递模型 ViewData View3
正如您所看到的,我正在尝试将我的模型从一个视图传递到另一个视图。但是,它导致了我的问题,因为当发布 View2 时,模型想要验证,但 View1 中的表单元素不再存在于 View2 中。
有没有办法告诉控制器不要第二次验证模型?
This is my setup:
Model => View1 => Validate Model
Model => View2 => I need to ignore Validation and just pass the Model
ViewData from Model => View3
As you can see, I'm trying to pass my Model from View to View. However, it's causing my problems because when View2 is posted, the Model wants to Validate but the form elements from View1 no longer exist in View2.
Is there a way to tell the controller not to Validate the Model that second time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信 ValidateInputAttribute 会跳过验证(这也将允许人们发布标记,这可用于 XSS 攻击,所以要小心)。这将跳过该操作的所有验证。
如果只有一些属性应该在一个操作方法上验证,而一组不同的属性应该在另一个操作方法上验证,那么您可能会遇到问题,但在这种情况下,我建议使用两个不同的视图模型。
I believe
ValidateInputAttribute
will skip validation (this will also allow people to post mark-up, which can be used for XSS attacks, so be careful). This will skip all validation for that action.If there are only some properties that should be validated on one action method, and a different set of properties that should be validated on another action method, then you might have problem, but in that scenario, I would suggest having two different view models.