0

In a View I send the model encoded like this:

var model = '@Html.Raw(Json.Encode(Model))';

to a Controller Action. The model is a list of movies, and each movies contains a release Date. This is the Controller action method

[HttpPost]
    public void createDoc(IEnumerable<Movie> movies)
    {
        //blablabla ...
        String date = "Date:" + movies.ElementAt(i).ReleaseDate + " ";
        //print date into a file
    }

When I print the date it is printed as Date:01/01/0001 00:00:00 The serialized data passed is shown with an alert and is printed as below: "/Date(1070233200000)/"

Receveing a list of movies in the createDoc controller action, I think the problem is at the beginnig: it saves in a wrong format the Date so I can't do anything to parse it in a right one. My model Movie for the Date proprierty is:

[DataType(DataType.Date)]
public DateTime ReleaseDate { get; set; }

Do I have to change something in the model class to store the Data in the right format passing it from View post to Controller Action or can I do something before sending or after receiving json data to parse it? Thanks.

Jack88PD
  • 615
  • 2
  • 10
  • 24
  • See this answer: http://stackoverflow.com/questions/726334/asp-net-mvc-jsonresult-date-format – moribvndvs Jun 08 '12 at 09:45
  • I already saw it, but I think my problem is a little bit different: I think I put somehow the wrong date for each movies in the list. – Jack88PD Jun 08 '12 at 09:59

1 Answers1

0

In your action method your assigning the date value to a String type so why not just use string.Format... something like:

String date = string.Format("Date: {0:dd MM yyyy}", movies.ElementAt(i).ReleaseDate)
Mark
  • 6,051
  • 2
  • 26
  • 25