jquery datatables - Return String instead of DateTime if LINQ Query NULL -


I am using JQuery Datatables with my MVC 5 application. I am implementing sorting on any of my datalet within my MVC controller. One of the columns displays the date to the user, and I want them to be able to sort this column, which works fine.

  // To sort different types of columns get the index of CollumnInndex = Convert ToInt32 (Request ["iSortCol_0"]); Function & lt; Survey_stats, datetime & gt; OrderingFunctionDate; Ordering FunctionDet = (C => c.InitiatedDate == Zero? Default (DateTime): c.InitiatedDate.Value);   

The problem is, at the moment, if c.InitiatedDate is zero, then I will change the default date back to 01/01/000 1, otherwise I return the actual date recorded in the database.

I do not like that I'm returning to the user 01/01/0001 , this is not great utility and can confuse them

The problem is that I

> ordering functionDATE = (C = & Gt; c.InitiatedDate == zero? Default (datetime): c.InitiatedDate.Value); With

ordering function = (c => c.InitiatedDate == empty? "No date is available": c.InitiatedDate .Value);

Because the function function & lt; Survey_stats, datetime & gt; The ordering procedure date is not returning , not a string, and I get an error in making this change. There is no unbalanced conversion between string and date time .

Can someone help me?

Thank you.

Any help would be appreciated.

You must use a nullible datetime and return null instead of a default date. Change your function prototype to:

  function & lt; Survey_stats, datetime? & Gt; OrderingFunctionDate;   

and content in:

  ordering function data = (c => c.InitiatedDate);   

Then I believe in jQuery datatiles that you can specify the value to use the data.

Comments

Popular posts from this blog

c# - Textbox not clickable but editable -

Matlab transpose a table vector -

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -