Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow null in model when using Code first

I have an model like this:

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

}

I use Mvc scaffolding for creating my controllers, repositories and views. Int the create View I'm not able to POST since I dont have values for "to" and "RequisitionID". I have not added [Required] to them. Is this possible? To POST and have those two null?

like image 994
espenk Avatar asked Jul 02 '13 09:07

espenk


1 Answers

To accept the null values you can use the following solution.

public int? RequisitionID { get; set; }
like image 153
Pramodi Samaratunga Avatar answered Oct 12 '22 22:10

Pramodi Samaratunga