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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:18:11+00:00 2026-05-13T17:18:11+00:00

This is a fairly recurring theme on StackOverflow, but once again I can’t get

  • 0

This is a fairly recurring theme on StackOverflow, but once again I can’t get my MVC controller action to recognise the data I’m trying to send. Any suggestions gratefully received.

My controller action looks like this:

        [Authorize]
        [HttpPost]
        public JsonResult Record(int task, string notes, double hours)
        {
            Repository<TimeEntry> TimeRepo = new Repository<TimeEntry>();
            ...

My Ajax call looks like this:

var Task = $('#time-task option:selected').val();
var Hours = parseFloat($('#time-hours').val());
var Notes = $('#txtNotes').val();

if (isNaN(Hours)) {
    Hours = 0;
}

$.post('/Home/Record', { task: Task, notes: Notes, hours: Hours }, function (data) {
    console.log(data);
});

And the exception returned is:

The parameters dictionary contains a
null entry for parameter ‘task’ of
non-nullable type ‘System.Int32’ for
method ‘System.Web.Mvc.JsonResult
Record(Int32, System.String, Double)’
in
‘JobTrack.Controllers.HomeController’.
An optional parameter must be a
reference type, a nullable type, or be
declared as an optional
parameter.
Parameter name:
parameters

There has to be something basic I’m overlooking, but damned if I can figure out where I’m going wrong. Suggestions appreciated.

Update: So changing the $.post to a $.ajax call and having that call use GET instead of POST appears to work. I suppose I can live with that but I’d rather be doing this correctly. Any suggestions as to why the HTTP Verbs should be making a difference?

  • 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-13T17:18:12+00:00Added an answer on May 13, 2026 at 5:18 pm

    ARGH!

    Knew it would be something basic I’d overlooked.

    The root cause of the problem was the /Scripts/globals.js file that I haven’t even been looking at (and had pretty much forgotten completely about). In that, I had the following code:

    $.ajaxSetup({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        data: "{}",
        dataFilter: function(data) {
            var msg;
    
            if (typeof (JSON) !== 'undefined' &&
            typeof (JSON.parse) === 'function')
                msg = JSON.parse(data);
            else
                msg = eval('(' + data + ')');
    
            if (msg.hasOwnProperty('d'))
                return msg.d;
            else
                return msg;
        }
    });
    

    The problem? ContentType. My understanding of the root cause is that since I’m using jQuery 1.4, the content type is being correctly determined automatically (“application/x-www-form-urlencoded”) and expressly defining it again in the global settings must confuse things somehow.

    Thanks for all who contributed to this solution. If anyone knows why the contentType causes Ajax posts to fail in jQuery, I’d love to get a deeper understanding.

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

Sidebar

Ask A Question

Stats

  • Questions 531k
  • Answers 531k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer [ ]{2,} SPACE (2 or more) You could also check… May 16, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer Using LINQ: var newDict = dict.Where(kvp => kvp.Value != 100)… May 16, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer If you have net-snmp installed, and you can execute programs… May 16, 2026 at 11:52 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a fairly simple script but something is going wrong and I can't
A fairly basic problem for a change. Given a class such as this: public
This is fairly difficult to explain. I am working on a text adventure at
There are a number of discussions on stackoverflow.com about what is the best iPhone
This might be impossible to answer since there are probably too many variables here,
Judging from the title, I kinda did my program in a fairly complicated way.
The using(...) statement is syntactic sugar for try{} finally {}. But if I then
I am starting to write a moderately sized project in C++ requiring a fairly
So thanks to many of the replies from this board, I have a much
I'm trying to change the backcolor of a .Net GridView when a certain condition

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.