0

I have a datetime picker that works for some specific date i.e 01-08-2019 to 12-08-2019. If i select a date outside that range (at least I tried about 20 other different dates) I get an error Please i need help with it.

I have tried changing the jquery code but it is the same.

c#

public ActionResult GetTransactions(string terminal, string branch, DateTime date) {
    List < ATM_TRANSACTIONS > trans = null;
    using(var context = new TestEntities2()) {
        var query = from st in context.ATM_TRANSACTIONS
        where st.branch_code == branch
        where st.terminal_id == terminal
        where st.transaction_date == date.Date
        select st;

        trans = query.ToList < ATM_TRANSACTIONS > ().ToList();

    }
    //var resp =  Json(trans, JsonRequestBehavior.AllowGet);
    //return resp;
    //Transactions(trans);
    ViewBag.trans = trans;
    ViewBag.terminal = terminal;
    ViewBag.branch = branch;
    ViewBag.date = date;
    return View();
}

html

<div class="col-xs-3">
    <div class="box" id="box3">
        <div class="box-header">
            <div class="form-group">
                <label for="TransactionDate">Transaction date</label>
                @*<input type="date" id="trans_date" class="form-control datepicker" style="width: 100%;">*@
                <div class="input-group date form-group">
                    <input type="text" id="t_date" name="date" class="form-control" value="@ViewBag.date"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
                </div>

            </div>
        </div>

jquery

 $('#t_date').datepicker({
                format: "dd/mm/yyyy",
                //keyboardNavigation: false,
                //forceParse: false,
                todayHighlight: true,
                autoclose: true,
            });

I am getting error message

The parameters dictionary contains a null entry for parameter 'date' of non-nullable type 'System.DateTime' for method 'System.Web.Mvc.ActionResult GetTransactions(System.String, System.String, System.DateTime)' in 'XYZPortal.Controllers.AdminController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

mplungjan
  • 169,008
  • 28
  • 173
  • 236
MMM
  • 23
  • 1
  • 1
  • 7
  • Yes i checked, in those cases the value wasn't being passed but in this case, it works sometimes and doesn't other times and it is the same date picker being used and calling the same controller action – MMM Aug 15 '19 at 14:26
  • Thank you mplungjan I found post with similar issue and this worked for me - https://stackoverflow.com/questions/26711248/bootstrap-datepicker-return-null-from-view-to-controller – MMM Aug 15 '19 at 14:51

0 Answers0