We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

DatepickerFor Validation

Hi,

in my Form I use Validation with annotations to guide the user. It's client side validation so these flags are set in the webconfig. So I included @Scripts.Render("~/bundles/jqueryval") in my Layout.
I used DatepickerFor to set the Date for some DateTimes of my Viewmodel. I changed the DateFormat but now as soon as the user picks another date, the datepicker is not valid anymore.

Can I somehow get the validation to work?

For your convenience I created an example that generates the exact behavior and is reduced to the core of the problem.

Kind Regards,
Torbian Linz

Attachment: DatePickerForTest_444be4e5.zip

1 Reply

KC Kasithangam C Syncfusion Team April 2, 2015 12:56 PM UTC

Hi Torbian,

We have analyzed your query.The issue ” the user picks another date, the datepicker is not valid anymore” is might have occurred because datatype mismatch while passing the date to the datepicker control.To resolve this issue,please specify the date datatype as string as shown below in model,

<code>

public class DateExample

{

public string dt { get; set; }
}
</code>

Please use the below code to set the value in datepicker control,
<code>

public ActionResult DatePickerFeatures()

{

DatePickerProperties datemodel = new DatePickerProperties();

datemodel.Locale = "en-US";

datemodel.DateFormat = "dd.MM.yyyy";

ViewData["date"] = datemodel;


DateExample d = new DateExample();

d.dt = System.DateTime.Now.ToString();

return View(d);
}
</code>

Also, we have modified your sample based on this and its available under the following location,

Sample: Sample

Please let us know if you need any assistance.
Regards,

Kasithangam


Loader.
Live Chat Icon For mobile
Up arrow icon