简体   繁体   English

mvc3中的客户端验证相关字段

[英]client side validation in mvc3 for dependent fields

Hi I have an MVC3 appliocation and using client side validation and find it to be very usefull. 嗨,我有一个MVC3应用程序,并使用客户端验证,发现它非常有用。 I am having 2 issues while using it. 我在使用时遇到2个问题。 -One is there any possiblity of Required filed dependency as it there for Compare eg: If the value of a particular filed say status is="Test" then the value of other say status done field must be not blank otherwise it can be blank. -一个可能存在需要归档的依赖项,因为它可以进行比较,例如:如果特定归档的状态为status =“ Test”,则其他状态完成字段的值不能为空,否则可以为空。 - I am having a dropdown say state .If its value is "Other" then need to make a textbox visible say "other state" .For know I am using javasript to make it visible. -我有一个下拉菜单,说state。如果其值为“ Other”,则需要使文本框可见,并说“ other state”。要知道我正在使用javasript使其可见。 I donot want to use javasript for that. 我不想为此使用javasript。 Can this be performed without using javascript. 可以在不使用JavaScript的情况下执行此操作。

You need to write your own custom compare attribute or simply use javascript. 您需要编写自己的自定义比较属性或仅使用javascript。 Nothing is built in that will do this for you. 没有内置的功能可以为您做到这一点。 The other option is to provide server side validation in your controller method where you check this situation and if it fails use ModelState.AddError to give a custom validation error. 另一个选择是在检查这种情况的控制器方法中提供服务器端验证,如果验证失败,请使用ModelState.AddError给出自定义验证错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM