0

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}

  • possible duplicate of [Display DateTime value in dd/mm/yyyy format in MVC4](http://stackoverflow.com/questions/18288675/display-datetime-value-in-dd-mm-yyyy-format-in-mvc4) – Brad Rem Mar 09 '14 at 17:52
  • Are you using Chrome by any chance? I found their "smart" date fields tend to force US date encoding (I am in the UK). Wound up avoiding that by removing the date attribute off the inputs :( – iCollect.it Ltd Mar 09 '14 at 21:17
  • No, the problem is because I'm used a GET method, which doesn't consider the uiCulture set in the web.config...so I have to change it to POST, but yet still I need to solve it using the GET method with Model Binder http://weblogs.asp.net/melvynharbour/archive/2008/11/21/mvc-modelbinder-and-localization.aspx – user3399059 Mar 09 '14 at 23:36

1 Answers1

0

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