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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:31:22+00:00 2026-05-31T19:31:22+00:00

MVC 2 I’m trying to post to an MVC action using jQuery, but I’m

  • 0

MVC 2

I’m trying to post to an MVC action using jQuery, but I’m getting an exception stating that id is null. Do I need some sort of attribute on the controller action to accept json packets like this? Something else I’m missing?

[HttpPost]
public ActionResult SearchCategory(int id, string SearchTerm, int PageNumber, int SiteIdFilter)
{
    return Json(AssociationsDao.SearchCategory(id, SearchTerm, PageNumber, SiteIdFilter));
}

post('<%= Url.Action("SearchCategory") %>', 
    JSON.stringify({id: 12, SearchTerm: '', PageNumber: 1, SiteIdFilter: 1}), 
    function(d) { alert(d); });

function post(targetURL, dataInput, success) {
    $.ajax({
        url: targetURL,
        type: "POST",
        contentType: "application/json; charset=utf-8",
        data: dataInput,
        dataType: "json",
        success: success,
        async: true
    });
}

From the Chrome developer tools, this is the exception:

The parameters dictionary contains a null entry for parameter ‘id’ of
non-nullable type ‘System.Int32’ for method
‘System.Web.Mvc.ActionResult SearchCategory(Int32, System.String,
Int32, Int32)’ in
‘Current.Web.BackOffice.WebUI.Controllers.SiteProductAssociationsController’.
An optional parameter must be a reference type, a nullable type, or be
declared as an optional parameter. Parameter name: parameters


EDIT

Here’s a screenshot of the post data from chrome; I can’t see anything wrong with it:

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-05-31T19:31:23+00:00Added an answer on May 31, 2026 at 7:31 pm

    Modify the post function to this:

    function post(targetURL, dataInput, success) {
        $.ajax({
            url: targetURL,
            type: "POST",
            data: dataInput,
            success: success,
            async: true        
        });
    }
    

    MVC is smarter than asmx web services. Instead of insisting on a json string, you can, in fact need to, just pass a plain JavaScript object. See this answer for more information.

    When you give jQuery’s $.ajax() function a data variable in the form
    of a javascript object, it actually translates it to a series of
    key/value pairs and sends it to the server in that manner. When you
    send the stringified json object, it’s not in that form and the
    standard model binder in mvc/mvc2 won’t cut it.


    Also note that the async parameter is superfluous since true is the default value, but that won’t hurt anything.

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

Sidebar

Related Questions

(Using MVC 2) From inside my controller action, I need to display the url:
Using MVC and trying to use dependency injection for controllers, but when I try
MVC use action attributes to map the same view for http get or post:
Using MVC with an observer pattern, if a user action requires polling a device
MVC @Html.TextBoxFor(model => model.SomeNotNullableType) When using this helper, if I have a type that
MVC 3. Vb.net. Part of my app generates PDF files using Itextsharp. Some strings
MVC 3 RTM. I have an action that returns a file (image/jpeg). I am
In MVC 3 project, I have a Controller action that returns a View. Let's
Using MVC 3 RTM I'm getting a strange NullReferenceException : @helper TestHelperMethod() { var
Using MVC 3 RTM and MvcContrib/FluentHtml version 3.0.51.0, I can't get the jQuery client

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.