This is a migrated thread and some comments may be shown as answers.

DateTime null in ActionResult

1 Answer 972 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Fabio
Top achievements
Rank 1
Fabio asked on 07 Nov 2019, 02:06 PM

Hi,

I'm trying to pass a DateTime value (Start_Date) to an ActionResult used by a template, but seems it is always null (other arguments string and int format are ok), changing type from dateTime to string seems to work, the value is a not null datetime string version but I would like to use directly the datetime, any suggestion?

 

(index.cshtml)

            columns.Bound(p => p.Start_Date).Format("{0:dd/MM/yyyy}");
            columns.Template(@<text></text>).ClientTemplate(
                                    "<a href='" +
                                         Url.Action("Details", "Data_Values") +
                                         "/?ContactID=#=Contact_ID#&SerialNumber=#=Serial_Number#&StartDate=#=Start_Date#'" +
                                    ">Details</a>").Width("100px");

(controller Data_ValuesController)

public ActionResult Details(int? ContactID, DateTime? StartDate, String SerialNumber)
        {

[...]

 

1 Answer, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 11 Nov 2019, 08:37 AM

Hi Fabrizio,

I would suggest you convert the Date to n ISO string and send it this way as a part of the query parameters:

columns.Template(@<text></text>)
	.ClientTemplate(
		"<a href='" + Url.Action("Details", "Home") +
		"/?SerialNumber=#=Serial_Number#&StartDate=#=Start_Date.toISOString()#'" +
		">Details</a>")
	.Width("100px");

Attached you will find a small sample implementing the above. Note that in order to test it, you will need to include the Kendo.Mvc.dll.

Regards,
Veselin Tsvetanov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
General Discussions
Asked by
Fabio
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Share this question
or