Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7601541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:11:19+00:00 2026-05-30T23:11:19+00:00

When I post a json object with a date property to a ApiController it

  • 0

When I post a json object with a date property to a ApiController it won’t deserialize into a date.

Server site code:

public class MegaTestController : ApiController
{
    // POST /megatest
    public void Post(ttt value)
    {
        string sdf = "!sad";
    }
}

public class ttt
{
    public DateTime Date { get; set; }
    public string Name { get; set; }
}

Then I do a POST request with fiddler

POST http://localhost:62990/MegaTest HTTP/1.1

User-Agent: Fiddler

Host: localhost:62990

Content-Type: text/json

Content-Length: 54

{
“Date”:”/Date(1239018869048)/”,
“Name”:”Dude”
}

But the object coming in only has the Name property set, the Date property is {01.01.0001 00:00:00}

Am I missing any headers or project settings?


Edit: The requests are actually coming from a HttpClient. Is it possible to format the date before sending the request over with HttpClient?

public Task<T> Create<T>(T item)
{
    var service = new HttpClient();
    service.BaseAddress = new Uri("http://localhost:62990");

    var method = typeof(T).Name + "s"; // in this case it will be ttts

    var req = new HttpRequestMessage<T>(item);
    req.Content.Headers.ContentType = new MediaTypeHeaderValue("text/json");

    return service.PostAsync(method, req.Content).ContinueWith((reslutTask) =>
    {
        return reslutTask.Result.Content.ReadAsAsync<T>();
    }).Unwrap();
}

var data = new ttt { Name = "Dude", Date = DateTime.Now };
Create(data);

Edit: This is a known bug with the ASP MVC 4 Beta and the final version of ASP MVC 4 will use Json.net as a json serializer until then you can use the default XML serializer or switch out the default Json serializer for Json.net. More info can be found on hanselman blog

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:11:22+00:00Added an answer on May 30, 2026 at 11:11 pm

    This is a known bug with the ASP MVC 4 Beta and the final version of ASP MVC 4 will use Json.net as a json serializer until then you can use the default XML serializer or switch out the default Json serializer for Json.net. More info can be found on hanselman blog

    Here is a small example of using the default XML Serializer to send DateTime with HttpClient:

    var service = new HttpClient();
    service.BaseAddress = url;
    
    var mediaType = new MediaTypeHeaderValue("application/xml");
    XmlMediaTypeFormatter formater = new XmlMediaTypeFormatter();
    var req = new HttpRequestMessage<T>(item, mediaType, new MediaTypeFormatter[] { formater });
    
    service.PutAsync(method, req.Content);
    

    But if you would like to use json then here is a good blog post on using JSON.NET with ASP.NET Web API

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to post a JSON object through a POST. I'm trying to do
I am posting a json object to an ASP.Net MVC controller with C# code.
In this post I learned how to encode an object on the server side,
I am trying to post a JSON-object to a REST webservice from an Android
first post ever here I'm trying to replicate this sort of JSON object so
I am using an XMLHttpRequest to POST a JSON string to PHP. The JSON
I don't have any idea how to post a JSON RPC request using Obj-C.
how to use serializeRowData option with editRow method in jqgrid to post a json
I have a nested json. I want to post it as a form input
$.post($(this).attr(action), $(this).serialize(), function(json) { alert('red'); AddItemAjax(json); }, json); This works in Chrome but not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.