Reputation: 617
I'm developing a .NET MVC application. In my .cshtml file I have provided a simple calendar tool in one of my textbox as follows :
<input class="form-control" id="createdOn" type="text" />
Here's the JS script for it:
$(document).ready(function ()
{
$("#createdOn").datepicker();
}
Now I want to check whether the user has selected any date in the above metioned text box or not in one of my C# file.
I have a LINQ query which retrieves data and is stored in a variable named "query".
So the code in this C# file goes like this :
var query = ( from //and so on
select {
// data to fetch
}
//below is where I'm stuck
if (!string.IsNullOrEmpty(sc.CreatedOn)) // here sc is an entity
{
query.Where(w => w.CreatedOn == sc.CreatedOn);
}
return query.ToList();
}
So here the above IF Block doesn't seems to validate the CreatedOn properly. What am I doing wrong? Can anyone tell a better way to validate it?
Upvotes: 0
Views: 77
Reputation: 950
First, check rather of not your sc.CreatedOn is a DateTime already in your entity.
if yes, then you may need to apply another method to check existence of the CreatedOn,
Normal datetime field
DateTime dat = new DateTime();
if (dat==DateTime.MinValue)
{
//unassigned
}
and in case, DateTime
DateTime? dat = null;
if (!dat.HasValue)
{
//unassigned
}
More information From: How to check if a DateTime field is not null or empty?
Upvotes: 1