0

I have a form using html helpers like this:

@using (Html.BeginForm("GuardarCliente", "Cliente"))
{
    @Html.LabelFor(m => m.FechaDeNacimiento)
    @Html.TextBoxFor(m => m.FechaDeNacimiento, new { @class = "form-control", placeholder = "Fecha de Nacimiento...", style = "width:74%; " })
    <div class="row">
        @Html.ValidationMessageFor(m => m.FechaDeNacimiento)                                
    </div>                            
    @Html.HiddenFor(m => m.Id)
    @Html.AntiForgeryToken()

   <button class="btn btn-primary">Save</button>

}

But i want to transform this input into Kendo datetime picker like this:

 $("#FechaDeNacimiento").kendoDateTimePicker({
    value: new Date(),
    culture: "es-ES",
    dateInput: true
 });

Then when i cliked the save button is sending null value in the controller, why is that? How can i fix this with jQuery and not using the ASP.NET MVC wrapper of kendo?

Juan José
  • 193
  • 2
  • 3
  • 22

2 Answers2

0

I'm not sure if ASP.Net is rendering id attribute in your element, but try this:

$("#@Html.IdFor(m => m.FechaDeNacimiento)").kendoDateTimePicker({ ...

If that doesn't works, set the id by yourself:

@Html.TextBoxFor(m => m.FechaDeNacimiento, new { id = "FechaDeNacimiento"... })

Your widget initialization is ok I think.

DontVoteMeDown
  • 21,122
  • 10
  • 69
  • 105
  • @JuanJosé `$('[name="FechaDeNacimiento"]')` ?? – DontVoteMeDown Oct 20 '17 at 15:48
  • sorry for making lose your time, it was just my mistake, the problem was for the culture, since in the bundle class I had a different reference for the culture that I put in the widget of kendo datetime picker. At least when i fixed that It worked back without problems – Juan José Oct 20 '17 at 20:12
0

Do you have the input element inside your HTML form? You'll need something like this:

<input id="FechaDeNacimiento" style="width: 74%" />

or, modify your existing razor code to add id attribute:

@Html.TextBoxFor(m => m.FechaDeNacimiento, new { @class = "form-control", id = "FechaDeNacimiento", placeholder = "Fecha de Nacimiento...", style = "width:74%; " })
SJaka
  • 712
  • 13
  • 40