2

这是我的模型:

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; }
  }

这个模型被我网站上的多个页面使用。请帮助我了解如何仅在某些页面上启用/禁用此遥控器?

谢谢

4

1 回答 1

3

我会为每个视图创建单独的视图模型,并从所有通用的类中继承

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;}
}
于 2012-06-24T15:45:48.733 回答