Set format to a Datetime in a function (ASP.Net MVC 4)

I have been having headaches with this function so I need a little help. Describing a little bit there is one class which has this attribute:

public class SessionDate
{
    ...
    [DisplayFormat(DataFormatString = "{0:d}")]
    public DateTime? searchValue2 { get; set; }
    ...
}

and there is a interface that has this function

public interface ISessionDate
{
     IEnumerable<SessionDate> Search (string searchName, Datetime? searchDate)
}

which is declared in another class

public class SessionDateHelper
{
     IEnumerable<SessionDate> Search (string searchName, Datetime? searchDate)
     {
          ...
     }
}

The problem is that the searchvalue2 is invoked in the View (inside the MVC 4 logic), which is set to dd/M/yyyy date format, but when I invoke the search in the Controller, somehow it goes rearranged to M/dd/yyyy, making the input change completely. For example I introduce 09/03/2014 (March 9th, 2014), but when it reaches the service it gets 03/09/2014 (Sept 03rd, 2014), how can I set that the function in the Interface and Helper automatically sets the date to {0:d}

Answers


The problem was that using GET method doesn't consider uiCulture, therefor it's set as default. To solve that you need a Model Binder, like this Model Binder


Need Your Help

Race condition firing events in AS3

flash actionscript-3 events race-condition

I have some troubles firing and removing events in the right chronicle order. The code below gives the following output: