0

I have a page with many date fields, which can be dynamically added on client side. I have a DatTime? property on editor template for this field:

[Display(Name = "Bar Admission Date")]
public DateTime? AdmissionDate { get; set; }

When I'm submitting a form I get a null data in AdmissionDate field because binder doesn't know the format of the field.

I have 2 ideas of how t oovercome this issue:

  1. Make a string field in model and parse it on a server side. Simple and pretty quick.
  2. Write a custom model binder for date fields. I don't like this solution because I don't know the keys for all fields that I will use.

Is there better solution? I searched how can I overload TextboxFor method in order to pass it a culture, but I didn't find

valerii.sverdlik
  • 559
  • 4
  • 18

1 Answers1

0

Sounds like you should use an enumerable (IList/ICollection) of DateTime?. Phil Haacked has a good article on model binding to a list (even when the number of items is dynamic).

Updated

As for the formatting problem, I would look at how to set the culture for the project/model binder.

Community
  • 1
  • 1
Erik Philips
  • 53,428
  • 11
  • 128
  • 150