I want to send Date to Controller by using bootstrap Date-time Picker but getting error
The parameters dictionary contains a null entry for parameter 'date' of non-nullable type 'System.DateTime' for method
Here is my model class
public class Slot
{
public DateTime DateSlots { get; set; }
public DateTime Starttime { get; set; }
public DateTime EndTime { get; set; }
}
Controller
[httPost]
public ActionResult Createslots(string startTime, string endTime, DateTime date)
{
using (MYDb db = new MYDb())
{
Slot obj = new Slot();
obj.Starttime = Convert.ToDateTime(startTime);
obj.EndTime = Convert.ToDateTime(endTime);
obj.DateSlots = date;
db.Slots.Add(obj);
db.SaveChanges();
}
return View();
}
// my Action
public ActionResult Createslots()
{
return View();
}
View
@using (Html.BeginForm("Createslots", "slot", FormMethod.Post))
{
<div class="col-sm-6 form-group">
@Html.LabelFor(model => model.DateSlots )
@Html.EditorFor(model => model.DateSlots , new { htmlAttributes = new { @class = "form-control" } })
</div>
<div class="col-sm-6 form-group">
@Html.LabelFor(model => model.Starttime)
@Html.EditorFor(model => model.Starttime, new { htmlAttributes = new { @class = "form-control" } })
</div>
<div class="col-sm-6 form-group">
@Html.LabelFor(model => model.EndTime)
@Html.EditorFor(model => model.EndTime, new { htmlAttributes = new { @class = "form-control" } })
</div>
<input type="submit" class="btn text-center" value="Submit" style="background: rgb(15, 94, 125);" />
}
here is Front end Img
start time and end time i easily get but when i try with Date then getting this of type Error
The parameters dictionary contains a null entry for parameter 'date' of non-nullable type 'System.DateTime' for meth
Note i also try null-able i case of date store null
public ActionResult Createslots(string startTime, string endTime, DateTime ? date)
{
}