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 4616338
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:58:01+00:00 2026-05-22T01:58:01+00:00

I am using JQUERY ajax to call an MVC method: JQUERY: $.ajax({ type: POST,

  • 0

I am using JQUERY ajax to call an MVC method:

JQUERY:

$.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "/Home/GetApplication/" + id,
            dataType: "json",
            data: '',
            timeout: 10000,
            success: function (obj) {

                $('#Name').val(obj.Name);
                $('#ApplicationIdentifier').val(obj.ApplicationIdentifier);
                $('#Frequency').val(obj.FrequencyValue);
                var d = new Date(parseInt(obj.BaseDate.substr(6)));
                $('#BaseDate').val(d.getMonth() + '/' + d.getDay() + '/' + d.getFullYear());

            },
            error: function () {
                return;
            }
        });

MVC Method:

[HttpPost]
        public ActionResult GetApplication(int id)
        {
            return Json(new Application
                            {
                                Name = "Testing",
                                ApplicationIdentifier = "123ABC",
                                FrequencyValue = 1,
                                FrequencyType = 1,
                                BaseDate = DateTime.Now
                            });
        }

All of this works fine except the date appearing on my form is 4/5/2011 and it should be 5/13/2011. Am I missing something here? Thanks.

  • 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-22T01:58:02+00:00Added an answer on May 22, 2026 at 1:58 am

    Working with dates and times between JavaScript and .NET can be difficult, and we usually handle this in our applications by always making the interaction in Unix Time:

    [HttpPost]
    public ActionResult GetApplication(int id)
    {
        DateTime unixTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
    
        return Json(new Application
            {
                Name = "Testing",
                ApplicationIdentifier = "123ABC",
                FrequencyValue = 1,
                FrequencyType = 1,
                BaseDate = (DateTime.Now - unixTime).TotalMilliseconds
             });
    }
    

    Now that your JavaScript application has the Unix Time, it can easily be converted to a Date (you are also formatting your date string incorrectly):

    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/Home/GetApplication/" + id,
        dataType: "json",
        data: '',
        timeout: 10000,
        success: function (obj) {
            var d = new Date(obj.BaseDate);
            var dateString = (d.getMonth() + 1) + '/' + d.getDate() + '/' + d.getFullYear();
    
            $('#Name').val(obj.Name);
            $('#ApplicationIdentifier').val(obj.ApplicationIdentifier);
            $('#Frequency').val(obj.FrequencyValue);
            $('#BaseDate').val(dateString);
        },
        error: function () {
            return;
        }
    });
    

    Also, I wouldn’t return your EF entity to the front-end, only give it what it really needs. By using a dynamic object, your types can be inferred here, and BaseDate becomes whatever type you give it:

    [HttpPost]
    public ActionResult GetApplication(int id)
    {
        DateTime unixTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
    
        return Json(new { 
                Name = "Testing",
                ApplicationIdentifier = "123ABC",
                FrequencyValue = 1,
                BaseDate = (DateTime.Now - unixTime).TotalMilliseconds
             });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using jQuery to make an Ajax call using an Http Post in ASP.NET
I am using jQuery to make an AJAX call to a ruby method in
I trying to make my first AJAX with JSON call using jQuery and CodeIgniter.
How would you access the cache from a jQuery ajax call? I'm using jquery
I am loading feed-items into a ul using this jQuery .ajax() call, which I
I'm using JQuery to make an Ajax call. I used a sniffer to catch
I am trying to pass a dataString to to an ajax call using JQuery.
Help! I am using jQuery to make an AJAX call to fill in a
I am using Rails and jQuery, making an ajax call initiated by clicking a
I am using .Net framework 2.0 / jQuery to make an Ajax call to

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.