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

The Archive Base Latest Questions

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

I have a form in HTML which when submitted makes a call to the

  • 0

I have a form in HTML which when submitted makes a call to the server using jQuery.ajax(); like so…

$.ajax({
    url: '/MyArea/MyController/Search',
    data: JSON.stringify($('#myForm').serializeObject()),
    type: "POST",
    dataType: 'json',
    contentType: 'application/json; charset=utf-8',
    success: function (data) {
         // Output the results to a table.
    }
});

The MVC action it calls takes the params and sends back a load of JSON which is displayed in lovely table….it all works just fine.

I now need to introduce a button which will send back the results in a CSV format.

So I’m using the exact same method….

[1] $(‘#myForm’).serializeObject()

[2] JSON.stringify the result of [1]

…but I add the step of using $.param() on the result of [2] like so….

window.location.replace('/MyArea/MyController/DownloadCSV?' + $.param(JSON.stringify($('#myForm').serializeObject()), true));

It all works fine unless dates are included the form.

Looking at fiddler I can see that the request looks like this…

/MyArea/MyController/DownloadCSV?referenceNo=102&startDate=01%2F04%2F2011+00%3A00&endDate=31%2F10%2F2011+23%3A59&pageNo=0&pageSize=15&sortBy=&sortDir=true 

….and I’m getting a 500 error….

The parameters dictionary contains a null entry for parameter 'endDate' of non-nullable type 'System.DateTime' for method 

If I remove the need for the dates then it all works just fine.

Any ideas how can I get this working?

I’m using latest jQuery with MVC3

Many 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-26T11:22:02+00:00Added an answer on May 26, 2026 at 11:22 am

    In GET requests the default model binder expects dates to be formatted using invariant culture format. Your request should look like this:

    /MyArea/MyController/DownloadCSV?referenceNo=102&startDate=2011-04-01&endDate=2011-10-31&pageNo=0&pageSize=15&sortBy=&sortDir=true 
    

    This obviously assumes that you have a corresponding controller action:

    public ActionResult DownloadCSV(SomeViewModel model)
    {
        ...
    }
    

    where SomeViewModel:

    public class SomeViewModel
    {
        public int ReferenceNo { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public int PageNo { get; set; }
        public int PageSize { get; set; }
        public string SortBy { get; set; }
        public string SortDir { get; set; }
    }
    

    Also your AJAX request seems a bit overcomplicated. You don’t need to convert into JSON. The following will work just fine:

    var form = $('#myForm');
    $.ajax({
        url: form.attr('action'),
        type: form.attr('method'),
        data: form.serialize(),
        success: function (data) {
             // Output the results to a table.
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an online gateway which requires an HTML form to be submitted with
I have a form which is submitted via ajax triggered by an image click,
I have a web application with HTML / jQuery which ic connected with AJAX
I have a form which submits user first and last name using POST signin.html
I have a html form which have a select list box from which you
I have this html form which has options: <tr> <td width=30 height=35><font size=3>*List:</td> <td
I have a an HTML form which contains the YAHOO rich text editor on
I have an HTML form generated by JSF which maps an input element to
I have a html form for uploading a file, which is as follows: $uploadhtml
I have a webrequest that returns a html response which has form inside with

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.