Showing the incorrect format

DateOnly data type not showing the correct format although the format is applied as per the below tag.


<ejs-datepicker ejs-for="IssuanceDate" id="IssuanceDate" format="dd/MM/yyyy" enabled="true"></ejs-datepicker>


1 Reply

PK Priyanka Karthikeyan Syncfusion Team January 23, 2024 10:47 AM UTC

Hi RJ ,

To address the issue, you should pass the date format as illustrated below:

Here is the modified code:

 public class DateValue

 {

     [Required(ErrorMessage = "Please enter the value")]

     public string value { get; set; }

 }

 public partial class DatePickerController : Controller

 {

     public IActionResult DatePickerFeatures()

     {

         DateValue val = new DateValue();

         val.value = DateTime.Now.ToDateOnly().ToString("dd/MM/yyyy");

         return View(val);

     }

[HttpPost]

     public IActionResult DatePickerFeatures(DateValue model)

     {

         DateValue val = new DateValue();

         val.value = model.value;

         return View(val);

     }

 }


If you prefer not to change the DateOnly type on the controller, an alternative approach is to set the datepicker value directly in the view. You can achieve this by using the following code:

    <ejs-datepicker id="datepick" format="dd/MM/yyyy" name="value" placeholder="Choose a Date" width="250px" value="@Model.value.ToString("dd/MM/yyyy")"></ejs-datepicker>

 

And to address the issue with the 'dateOnly nullable' type, it is essential to set the value in the following manner:

 <ejs-datepicker id="datepick" format="dd/MM/yyyy" name="value" placeholder="Choose a Date" width="250px" value="@Model.value?.ToString("dd/MM/yyyy")"></ejs-datepicker>


This code ensures that the datepicker displays the formatted date without modifying the DateOnly type in the controller. If this solution doesn't fully meet your specific requirements or if you have any further questions, please don't hesitate to let us know. We're here to assist you further and tailor the solution to your needs.

Regards,

Priyanka K


Loader.
Up arrow icon