通过asp.net Web表单应用程序中的web.config进行数据注释

时间:2022-12-21 21:11:33

Assume we have following code c#

假设我们有以下代码c#

  public class Customer
{
  [Required]
  [StringLength(50)]
  public string LastName { get; set; }
[Range(5, 50)]
  public int ReorderLevel { get; set; }

  [Range(typeof(Decimal),"5", "5000")]
  public decimal ListPrice { get; set; }

}

or in VB.NET

或者在VB.NET中

Public Class Customer
    <Required> _
    <StringLength(50)> _
    Public Property LastName() As String
        Get
            Return m_LastName
        End Get
        Set
            m_LastName = Value
        End Set
    End Property
    Private m_LastName As String
    <Range(5, 50)> _
    Public Property ReorderLevel() As Integer
        Get
            Return m_ReorderLevel
        End Get
        Set
            m_ReorderLevel = Value
        End Set
    End Property
    Private m_ReorderLevel As Integer

    <Range(GetType([Decimal]), "5", "5000")> _
    Public Property ListPrice() As Decimal
        Get
            Return m_ListPrice
        End Get
        Set
            m_ListPrice = Value
        End Set
    End Property
    Private m_ListPrice As Decimal

End Class

Is it possible to set the range and required switch on or off from web.config?

是否可以从web.config中设置范围和所需的开关?

This will help user to add/remove validations if business require a change. E.g. need to make one field required or optional.

如果业务需要更改,这将帮助用户添加/删除验证。例如。需要创建一个字段或可选。

Or change the range Cheers

或改变范围干杯

1 个解决方案

#1


You can disable client-side validation by setting the below in your config:

您可以通过在配置中设置以下内容来禁用客户端验证:

<add key="ClientValidationEnabled" value="false" />

#1


You can disable client-side validation by setting the below in your config:

您可以通过在配置中设置以下内容来禁用客户端验证:

<add key="ClientValidationEnabled" value="false" />