2015-05-06 77 views
0

假設我們有下面的代碼 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; } 

} 

或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 

是否有可能設置範圍和需要開啓或關閉web.config?

這將幫助用戶在業務需要更改時添加/刪除驗證。例如。需要使一個字段是必需的或可選的。

或更改範圍 乾杯

+0

讓你的客戶類實現IValidatableObject。然後您可以測試條件並在需要時應用驗證。 http://www.itorian.com/2013/02/custom-validation-with.html –

回答

0

您可以通過設置下面的在你的配置禁用客戶端驗證:

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