2012-06-24 95 views
2

這裏是我的模型:MVC 3有條件遠程驗證

public class StockRequestModel 
    { 
    public int StockID { get; set; } 
    public int CategoryID { get; set; } 
    public int ItemID { get; set; } 
    public string TranCode { get; set; } 

    [Remote("CheckAvailableStocks", "Validation", AdditionalFields = "ItemID")] 
    public int ItemQuantity { get; set; } 

    public decimal ItemValue { get; set; } 
    public int PurchaseOrderID { get; set; } 
    public int MaterialRequesitionID { get; set; } 
    public int ReturnedByID { get; set; } 
    public string Remarks { get; set; } 
    public DateTime LastUpdateDate { get; set; } 
    } 

這個模型,在我的網站上的多個頁面。請幫助我如何在特定頁面上啓用/禁用此遙控器?

感謝

回答

3

我會爲每個視圖創建和獨立的ViewModels 繼承它是通用於所有

public class StockRequestBase 
{ 
    public int StockID { get; set; } 
    public int CategoryID { get; set; } 
    public int ItemID { get; set; } 
    public string TranCode { get; set; } 
    //other common properties 
} 
public class AddStockRequest : StockRequestBase 
{ 
    [Remote("CheckAvailableStocks", "Validation", AdditionalFields = "ItemID")] 
    public int ItemQuantity { get; set; } 
} 
public class AddStockRequestOptional : StockRequestBase 
{ 
    public int ItemQuantity { get; set; } 
    public string AnotherSpecificAttribute { set;get;} 
} 
+0

非常感謝你的類! – samantha07

+0

@ samantha07:歡迎您:) – Shyju