Currently I have a DateTime property for a model. I am using the telerik MVC framwork but I am using a DateTime property and the editor column for this property is auto-generated so there is no code which controls it in my View or Controller. On Telerik's website there are instructions on how to set the default date time for a date time picker but this picker isn't initiated anywhere because it is in a column. The problem is I want to set the DateTime to be the current date and time if it isn't already specified. Currently, the code for the model looks like this:
public DateTime CreatedDate { get; set;}
I want it to do something more like this:
public DateTime CreatedDate
{
get
{
if (QuestionID != 0)
{
return this.CreatedDate;
}
else
{
return DateTime.Now;
}
}
set { CreatedDate = value; }
}
this way it will return the DateTime that is stored for this Question if the ID exists. If you are creating a new Question, it gets the current DateTime.
The problem is here with the Set. When I try to load up a screen, set get's a Stack Overflow. I'm really unfamilular with this kind of code, so I have no idea how to work with it.
Before we were not working with the model, and instead using JQuery to get the CreatedDate's data and set it to the current date time. The issue with that is when you go to the "picker" part of the date time, it goes to the default date time rather than the current one. this is why I want to set it through the Model, View, or Controller, and not with Jquery.
Let me know if you can help me understand Gets and Sets in the model!