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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:07:44+00:00 2026-06-12T03:07:44+00:00

I have an action method which have two string arrays as parameters, i am

  • 0

I have an action method which have two string arrays as parameters, i am posting this action method with ajax post method, i am having one problem, On controller i got both arrays data same
but i am making both arrays with different data(one contains code other contains name)
below is my code

 public ActionResult SectionBook(string[] cs,string[] cname)
{
}

var CourseSection=new Array();
var CourseName=new Array();
 $('a p-button').live('click', function () {    
        var schoolCourseId = $(this).attr('id');
        CourseSection.push(schoolCourseId);
        CourseName.push($(this).html().split("(")[0]);        
    });


 $('#btnSubmit').live('click', function () {

$.ajax({
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            url: '/MyController/SectionBook',
            //            dataType: 'json',
            data: $.toJSON(CourseSection, CourseName),
            success: function (result) {                
                window.location.href = '/MyController/SectionBooks'
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(thrownError);
            },
            async: false,
            cache: false
        });

});

i have debugged the JS code and both arrays are having different values here but in controller cs and cname contains same data

  • 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-12T03:07:46+00:00Added an answer on June 12, 2026 at 3:07 am

    I think the problem is that the toJSON method only takes one parameter and ignores the rest. So by doing
    $.toJSON(CourseSection, CourseName)
    You are only creating a JSON object with the values of the first array passed in.
    If you wrap the 2 arrays in and object however like this

    var CourseSection = new Array();
    var CourseName = new Array();
    CourseSection.push("cs1");
    CourseSection.push("cs2");
    CourseSection.push("cs3");
    
    CourseName.push("cn1");
    CourseName.push("cn2");
    CourseName.push("cn3");
    
    var newObj = {
     cn:CourseName,
     cs:CourseSection        
    };
    

    and then convert the newObj object to JSON with

    JSON.stringify(newObj)
    

    or

     $.toJSON(newObj)
    

    You should be able to retrieve the values from both arrays in the controller using JavascriptSerializer

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

Sidebar

Related Questions

In a php-script i have a form, method is post, action-attribute is empty, which
I have an action method that takes in two different objects. I am posting
I have an action method without parameters. The QueryString collection contain all of my
I have problem with ObjectContext.SaveChanges method: public void Save(Action<object, object> action) { EventAggregator.GetEvent<EntityServiceRequestingEvent>().Publish(true); var
My html of form is like this <form id=form method=post action=func.php> <table> <!--- DATA
I have created a radio group which contains two buttons, I can select one
I have this type that contains two overloads of a generic method. I like
I have written two methods that take and return a string. One converts from
I have two radio buttons, and depending on which one is selected I want
Hi Guys i have two tables which look like this usertable RoleTable ----------------------- ---------------------------

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.