简体   繁体   English

在View MVC中禁用验证

[英]Disable a validation in View MVC

I have a confused case with my project 我的项目有一个困惑的案例

My Modeler like 我的模特喜欢

public int ReasonSelected { get; set; }
public bool CardSelected { get; set; }

and ReasonSelected is a required field just if the CardSelected is true! 仅当CardSelected为true时, ReasonSelected是必填字段!

in the View I put a for statement as I have about 3 types of cards and what I need is to only show the validation message just if the user select the card so other unselected cards shouldn't raise the "Must select reason" error message View我放置了一个for语句,因为我有大约3种类型的卡,并且我只需要显示验证消息,即使用户选择了卡,其他未选择的卡也不应引发“必须选择原因”错误消息

Only if the user select a card, so must select a reason ... ReasonSelected validation should only works with selected cards not others 只有当用户选择一个卡,所以必须选择一个原因... ReasonSelected验证应只适用于选定的卡不是别人

You could write a custom validation [RequiredIf] attribute . 您可以编写自定义验证[RequiredIf]属性 You could bring this a step further and implement IClientValidatable to perform client side validation. 您可以更进一步,并实现IClientValidatable来执行客户端验证。

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

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