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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:11:27+00:00 2026-06-02T01:11:27+00:00

I hope anyone can help me (Sorry for my english). I have a problem

  • 0

I hope anyone can help me (Sorry for my english).
I have a problem when I want to send un array of arrays in ajax.
My model is:

public class SJSonModel
{
    public string Name { get; set; }
    public bool isChecked { get; set; }     
}

public class SJSonModelList
{
    public List<SJSonModel> Features { get; set; }
    public List<SJSonModel> MenuItems { get; set; }
}

The controller:

    [HttpPost]
    public ActionResult CheckPreferences(SJSonModelList postData)
    {
        BindUserFeatures(postData.Features);

        return Json(new { status = "Success", message = "Passed" });
    }

The View simplified:

<div class="Feature borderRadius Items">
    <h2>Title
        <input type="checkbox" class="Item" name="featureName"/>
    </h2> 

   <div class="FeatureDetails subItems">                 
        <a href="@Url…">featureName</a>
        <input type="checkbox" class="subItem" name="subItemName"/>
   </div> <!-- endOf FeatureDetails -->

The JQuery code:

    var isChecked = false;
    var features = new Array();
    var menuItems = new Array();
    var postData = new Array();

Here I fill the features, the menuItems with the featureName/menuItemName and isChecked boolean for each feature/menuItem

menuItems.push({ "Name": $(this).attr('name'), "isChecked": isChecked });
features.push({ "Name": $(this).attr('name'), "isChecked": isChecked });

postData.push({ "features": features, "menuItems": menuItems });
postData = JSON.stringify(postData);

The ajax function:

    $(':submit').click(function () {

        postData.push({ "features": features, "menuItems": menuItems });
        postData = JSON.stringify(postData);

        $.ajax({
                 url: '@Url.Action("CheckPreferences")',
                 type: 'POST',
                 data: postData, 
                 contentType: "application/json; charset=utf-8",
                 dataType: "json",
                 traditional: true,
                 success: function () { window.alert('@Resource.AjaxSuccess'); },
                 error: function (event, request, settings) {  window.alert('@Resource.AjaxError' + ' : ' + settings); },
                 timeout: 20000
        }); //endOf $.ajax
    }); //endOf :submit.click function

When I do alert(postData), in client side it contains the true values for each item but in the conroller the postData.Features and postData.MenuItems are null.

I have tried to pass just one array to the controller too:

 features = JSON.stringify(features);

in $.ajax:

{… data: features,…}

in controller:

 ActionResult CheckPreferences(IEnumerable<SJSonModel> features)

and it works fine, but I don’t know how to pass the array of json objects to my contoller. So I hope to retrieve the answer here 🙂

Thank you very much.

  • 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-02T01:11:29+00:00Added an answer on June 2, 2026 at 1:11 am

    Instead of combining your arrays into another array, you’re best of sending them as individual parameters to the action method, something like:

    Assume we still have your two arrays:

    var features = new Array();
    var menuItems = new Array();
    menuItems.push({ "Name": $(this).attr('name'), "isChecked": isChecked });
    features.push({ "Name": $(this).attr('name'), "isChecked": isChecked });
    

    Then in your JQuery ajax call do the following:

    $.ajax({
            url: '@Url.Action("CheckPreferences")',
            type: 'POST',
            datatype: "json",
            traditional: true,
            data: { 
                menuItems: JSON.stringify(menuItems),
                features: JSON.stringify(features)
            },
            success: function () { window.alert('@Resource.AjaxSuccess'); },
            error: function (event, request, settings) {  
                window.alert('@Resource.AjaxError' + ' : ' + settings); },
            timeout: 20000
    });
    

    Then your controller method should be:

    [HttpPost]
    public ActionResult CheckPreferences(string menuItems, string features)
    {
        var js = new JavaScriptSerializer();
        var deserializedMenuItems = (object[])js.DeserializeObject(menuItems);
        var deserializedFeatures = (object[])js.DeserializeObject(features);
        var myFeatures = new List<SJSonModel>();
        var myMenuItems = new List<SJSonModel>();
    
        if (deserializedFeatures != null)
        {
            foreach (Dictionary<string, object> newFeature in deserializedFeatures)
            {
                myFeatures.Add(new SJSonModel(newFeature));
            }
        }
    
        if (deserializedMenuItems != null)
        {
            foreach (Dictionary<string, object> newMenuItem in deserializedMenuItems)
            {
                myMenuItems.Add(new SJSonModel(newMenuItem));
            }
        }
    
        var myModelList = new SJSonModelList(myFeatures, myMenuItems);
    
        return Json("");
    

    I also edited your classes by putting in a constructor to work with the above code, like so:

    public class SJSonModel
    {
        public SJSonModel(Dictionary<string, object> newFeature)
        {
            if (newFeature.ContainsKey("Name"))
            {
                Name = (string)newFeature["Name"];
            }
            if (newFeature.ContainsKey("isChecked"))
            {
                isChecked = bool.Parse((string)newFeature["isChecked"]);
            }
        }
    
        public string Name { get; set; }
        public bool isChecked { get; set; }
    }
    
    public class SJSonModelList
    {
        public SJSonModelList(List<SJSonModel> features, List<SJSonModel> menuItems )
        {
            Features = features;
            MenuItems = menuItems;
        }
    
        public List<SJSonModel> Features { get; set; }
        public List<SJSonModel> MenuItems { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry my English is bad. I hope you can get what I want. I
I hope anyone can help me to fix a little problem. After getting a
I hope anyone can help. I have to develop up against this third party
I am stuck and in need of a hand. Hope someone can help? Anyone
I'm new here and I hope anyonte can help me. I have WCF Service
Hope the AWK gurus can provide a solution to my problem . I have
Really hope someone can help me as I'm a bit stuck :S I have
Hi guys I hope anyone can help me. I'm running a simple program in
hope you can help me! I have a form, which has a large amount
I'm having some problems with my stored procedure. Hope anyone can help me figure

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.