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 并让这两个为空?

4

2 回答 2

24

您应该使用可为空的类型声明可选字段

public int? RequisitionID { get; set; }
于 2013-07-02T09:12:00.380 回答
2

要接受空值,您可以使用以下解决方案。

public int? RequisitionID { get; set; }
于 2020-12-09T14:30:52.453 回答