12

私はこのようなモデルを持っています:

 public class EquipmentEmployee
{
    public int EquipmentEmployeeID { get; set; }

    public int EmployeeID { get; set; }
    public Employee Employee { get; set; }

    public int EquipmentID { get; set; }
    public Equipment Equipment { get; set; }

    public int RequisitionID { get; set; }
    public Requisition Requisition { get; set; }

    public DateTime From { get; set; }

    public DateTime To { get; set; }

    public string Comment { get; set; }

}

コントローラー、リポジトリー、およびビューの作成に Mvc スキャフォールディングを使用しています。「to」と「RequisitionID」の値がないため、作成ビューの内部で POST できません。[必須]は付けていません。これは可能ですか?POSTして、これら2つをnullにするには?

4

2 に答える 2

24

null 許容型を使用してオプションのフィールドを宣言する必要があります

public int? RequisitionID { get; set; }
于 2013-07-02T09:12:00.380 に答える