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.
In your action method your assigning the date value to a String type so why not just use string.Format… something like: