0

Very Simple question...

I have this action on the controller:

public ActionResult Index(DateTime? dataini, DateTime? datafim)
        {
            if((dataini != null) && (datafim != null))
            {
                var agendamento = db.agendamento.Where(x => x.data_agendamento >= dataini && x.data_agendamento <= datafim);
                return View(agendamento.ToList());
            }
            else
            {
                var agendamento = db.agendamento.Include(a => a.medico).Include(a => a.paciente);
                return View(agendamento.ToList());
            }


        }

And this in my view:

<p>
    @using (Html.BeginForm("Index", "agendamentos", FormMethod.Get))
    {
        <b>Data Inicial:</b>@Html.TextBox("dataini", null, new { @class = "form-control datepicker" })
        <b>Data Final:</b>@Html.TextBox("datafim", null, new { @class = "form-control datepicker" })
        <input type="submit" value="Filtrar por Data" />
    }
</p>

But i'm not receiving the parameter "datafim" from the filter. I'm only receiving the parameter "dataini". What i'm doing wrong ?

UPDATE: I forgot to put the url being passed:

http://localhost:50608/agendamentos/Index?dataini=10%2F05%2F2017+13%3A00&datafim=15%2F12%2F2018+14%3A00

UPDATE WITH THE ANSWER: I just needed to remove the FormMethod.Get of the view and everything worked out. Final code remained the same with this line changed:

@using (Html.BeginForm("Index", "agendamentos"))
1

1 Answer 1

1

If you see in the URL Date for datafim : 15/12/2018 and your method expecting a date which is formatted as "MM/dd/yyyy", so according to your date 15 is a day but method understands it like a month that's why its been NULL.

Sign up to request clarification or add additional context in comments.

1 Comment

I forgot that i opened this topic, thanks for the answer, but that wasn't the problem... To solve the problem i just removed the "FormMethod.Get" of this line: @using (Html.BeginForm("Index", "agendamentos", FormMethod.Get)) and everything worked out ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.