Hi @Analyst_SQL ,
You can use FormMethod.post to pass the date parameters from view to controller.
According to the format of Input Date, you need to change the DataFormatstring to "{0:MM-dd-yyyy}".
You can refer to the following code:
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<div class="form-horizontal">
<div class="form-group form-group-sm">
<div class="col-md-8">
<input name="start" type="date" id="datepicker" class="form-control" />
</div>
</div>
<div class="form-group form-group-sm">
<div class="col-md-8">
<input name="end" type="date" id="datepicker" class="form-control" />
</div>
</div>
<div class="form-group-sm">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" /> <span> </span>
</div>
</div>
</div>
}
[HttpPost]
public ActionResult Index(DateTime? start, DateTime? end)
{
var Test = (from q in DB.customer
where q.C_Date > start && q.C_Date < end
select q).ToList();
return View(Test);
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.