Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, i have three attributes of datetime: Time_start, Time_fail, Time_pass.

i want to get information between two date.

so in view, i will ask for datestart and dateEnd to get the date interval, and compare with the Time_Start

then, between three date, i want to choose the latest date to display. how to i code that?

What I have tried:

in view, i ask for date in textbox like this:

<div class="form-group">
                                           @Html.TextBox("DateStart", "", new { @class = "date-picker form-control", @placeholder = "Date Start", @autocomplete = "off" })
                                       </div>
                                       <div class="form-group">
                                           @Html.TextBox("DateEnd", "", new { @class = "date-picker form-control", @placeholder = "Date End", style = "visibility: visible !important" })

                                       </div>
                                       <button type="submit" value="Search" class="btn btn-primary">Search</button>


in controller:

public ActionResult TesterPerformance(DateTime DateStart, DateTime DateEnd)
       {
        var selectdate = (from c in db.Information
                           where c.Time_start >= DateStart && c.Time_start <= DateEnd
                           select new DetailBundle
                           {
                               Time_start = c.Time_start,
                               Time_fail = c.Time_fail,
                               Time_pass = c.Time_pass
                           }).ToList();
           ViewBag.datepick = selectdate;
           return View();


now, i'm missing the part to compare the latest date to view and i did not have any idea to code that.

using this code also i got error as it says "
The parameters dictionary contains a null entry for parameter 'DateStart' of non-nullable type 'System.DateTime' for method 'System.Web.Mvc.ActionResult TesterPerformance(System.DateTime, System.DateTime)' in 'StorageHost.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
"

please guide me through this as i'm still new with c# projects. thank you
Posted
Updated 14-Jul-20 21:36pm

1 solution

This is much the same issue as your question yesterday: How to code to display between two dates[^]. You must ensure that all the parameters you are trying to use actually contain valid data.

If you do not understand how parameters and objects are used in C# then you need to go back and study the language in more detail.
 
Share this answer
 
Comments
dlnzki 15-Jul-20 3:53am    
sorry for so many question. i already find the solution of why it got that error

public ActionResult TesterPerformance(DateTime? DateStart, DateTime? DateEnd)

error is because of the "?".

problem solved. thank you for your reply
Richard MacCutchan 15-Jul-20 4:17am    
It would have helped if you had shown that in your original question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900