Kadir.K
Kadir.K

Reputation: 376

Telerik MVC DatePicker Doesn't Bind to Model

I am trying to use Telerik MVC DatePicker in my project. Here is the situation:

  1. I have a model which have :

    ...
    [DataType(DataType.Date)]
    public System.Nullable<DateTime> EndDate { get; set; }
    ...
    
  2. My ProjectCreate view has strong type of the model given above

  3. Between

    @using (Html.BeginForm(null, null, FormMethod.Post, new { Class="ym-form ym-columnar" }))
    {
    ...
    }
    

    I have:

    @(Html.Telerik().DateTimePickerFor(c => c.EndDate)
                    .Name("EndDatePicker")
    
  4. Within my action

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult ProjectCreate(ProjectView view)
    {
    ...
    }
    

the

    view.EndDate

value is always null whichever date I choose.

I have googled a lot but couldn't find what the problem is.

Upvotes: 1

Views: 3093

Answers (1)

Atanas Korchev
Atanas Korchev

Reputation: 30671

That's because you are setting the Name of your datepicker. You don't need that when using DatePickerFor:

@(Html.Telerik().DateTimePickerFor(c => c.EndDate))

Upvotes: 3

Related Questions