如何避免特定元素的MVC客户端验证? [英] How to avoid MVC client side validation for specific element ?

查看:52
本文介绍了如何避免特定元素的MVC客户端验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我正在使用Clint端验证表单提交一些非空值以及一些 null-able 值,但我的验证不允许null-able values。



这里是我的查看模型



Hi
I am using Clint side validation for a form to submit some not null value and also some null-able Value but my validation not allowing null-able values.

here is my View Model

public int? ResourceId { get; set; }

       public int? Minutes { get; set; }

       [Required(ErrorMessageResourceName = "REQ_Gender", ErrorMessageResourceType = typeof(Resources.Messages))]
       public DateTime BookingDate { get; set; }

       [DataType(DataType.Time)]
       public DateTime? StartTime { get; set; }

       [DataType(DataType.Time)]
       public DateTime? EndTime { get; set; }

       public decimal? Price { get; set; }

       public bool IsFree { get; set; }

       public bool IsCourse { get; set; }

      [StringLength(500)]
       public string Reason { get; set; }

       public DateTime? PaymentDate { get; set; }


       public decimal? PartlyPaidAmount { get; set; }





但是在向Price和PartlyPaidAmount提交空值时,我将验证消息作为

字段价格必须是数字。和字段PartlyPaidAmount必须是一个数字。

请点击此链接查看结果:

https://app.box.com/s/4abvfvsjzt7m6jdk5u47 [ ^ ]



我只需要为Price和PartlyPaidAmount提交空值表格。



谢谢你,



But on submitting null value to Price and PartlyPaidAmount i am geting a validation msg as
"The field Price must be a number." and "The field PartlyPaidAmount must be a number."
please follow this link to see the result:
https://app.box.com/s/4abvfvsjzt7m6jdk5u47[^]

All i need is to submit the form with null value for Price and PartlyPaidAmount.

Thank you,

推荐答案

这是因为你已经将Validate属性应用于你的洞模型,删除验证模型中的属性并将其应用于强制性的个人。

希望这会对您有所帮助
this happens because you have apply Validate attribute to your hole model, remove validate attribute from your model and apply it to individual where it is mandatory.
Hope this will help you


这篇关于如何避免特定元素的MVC客户端验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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