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

  • SEARCH
  • Home
  • 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 9182747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:38:02+00:00 2026-06-17T18:38:02+00:00

When using Angular JS to post back to the server with a complex object

  • 0

When using Angular JS to post back to the server with a complex object the datetime and datetime? values do not bind correctly. I have tried JSON.stringify to no avail. I have posted a related question though possibly it was too general. What I really need to know is how to correctly pass those dates in. What I am currently doing is using workaround in js to convert the dates but I would rather not do that and simply get the dates in the form I need them when in Angular and then pass back the correct values.

How do you bind to those datetime/datetime? values correctly? Please see the following code example and Fiddler post results.

C# Class:

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime BirthDate { get; set; }
    public DateTime? ApprovedForSomething { get; set; }
}

Angular JS Controller:

function PersonController($scope, $http) {
    $scope.getPerson = function () {
        $http.get('../../Home/GetPerson/1').success(function (data) {
            $scope.Person = data;
        });
    }
    $scope.updateApprovedForSomething = function () {
        $http.post('../../Home/UpdatePerson', { person: $scope.Person }).success(function (data) {
            console.log(data);
        });
    }
}

Fiddler Post:

HTTP/1.1 200 OK Cache-Control: private Content-Type: application/json;
charset=utf-8 Server: Microsoft-IIS/8.0 X-AspNetMvc-Version: 4.0
X-AspNet-Version: 4.0.30319 X-SourceFiles:
=?UTF-8?B?YzpcdXNlcnNcbmlja1xkb2N1bWVudHNcdmlzdWFsIHN0dWRpbyAyMDEyXFByb2plY3RzXFZhbGlkYXRpb25UZXN0XEhvbWVcR2V0UGVyc29uXDE=?=
X-Powered-By: ASP.NET Date: Wed, 16 Jan 2013 14:48:34 GMT
Content-Length: 124

{“FirstName”:”Bob”,”LastName”:”Smith”,”BirthDate”:”/Date(695573315098)/”,”ApprovedForSomething”:”/Date(1358261315098)/”}

This is the result on the server side. The datetime binds to a new datetime value which is not correct and the datetime? is null.

enter image description here

  • 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-06-17T18:38:03+00:00Added an answer on June 17, 2026 at 6:38 pm

    If someone has better solution then please feel free to update the answer.

    There might be better solution out there but what I did is very simple workaround.
    Just create an encapsulation property for DateTime object to string and use that for binding purpose.

    public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public DateTime BirthDate { get; set; }
        public DateTime? ApprovedForSomething { get; set; }
        public DateTime BirthDateAsString 
        {
            get { return BirthDate.ToShortDateString();}
            set { DateTime.Parse(value, BirthDate);}
       }
    }
    

    Over http all objects are treated as strings and but ASP.NET is smart enough to provide Model Binding feature. However it is unable to bind the JavaScript Date object to .NET DateTime object.

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

Sidebar

Related Questions

Validation does not work with Input::json. Ive tried different ways using json_decode/using arrays but
I have several TextBoxes, which display angular values. I format these using different custom
I'm trying to create a POST request using angular.js to this Django view. class
I'm creating two POST calls. One using a django form and one using angular
I have an chtml page using Angular Js that contains list with objects from
I have created a simple code editor using Angular JS & old fashioned JavaScript
Angular.js, when accessing a web service using the $http object, automatically adds a X-Requested-With:XMLHttpRequest
I am using angular's $http.jsonp() request which is successfully returning json wrapped in a
I have an angular js app. I am using gapi to sign in and
I just started using angular.js , and it is pretty useful. I have searched

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.