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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:59:48+00:00 2026-05-30T12:59:48+00:00

I have a MVC action method from which I am returning the data as

  • 0

I have a MVC action method from which I am returning the data as in the image below.

Action Method

[HttpPost]
public JsonResult LegalCheck(string jsonPackage)
{
    var serializer = new JavaScriptSerializer();
    var comments = serializer.Deserialize<Dictionary<string, string>>(jsonPackage.Substring(jsonPackage.IndexOf('{'), jsonPackage.LastIndexOf('}')));
    var results = MyService.GetViolations(comments, CookieManager.ClientId);
    return Json(results);
}

enter image description here

results holds the text area Id’s(CommentTextarea-1181_1183, etc) and needed data under that. How can i loop thorough the results? results.length, results[0] is showing as undefined. Is it possible to loop through this Json data or will have to change the json data that is being returned?

The data int he action method is as below

results
Count = 2
    [0]: {[CommentTextarea_1181_1183, Mynamespace.Services.Legal[]]}
    [1]: {[CommentTextarea_1181_1184, Mynamespace.Services.Legal[]]}

]}

Legal ia class as below

 [Serializable]
    public class Legal
    {
        public string Phrase { get; set; }
        public int StartIndex { get; set; }
    }

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-30T12:59:50+00:00Added an answer on May 30, 2026 at 12:59 pm

    It seems that the MyService.GetViolations method returns a Dictionary<string, Legal[]>. The JavaScriptSerializer that is used by ASP.NET MVC 3 to serialize your JSON response doesn’t generate a javascript array when serializing a dictionary. It generates a javascript object. So you cannot loop because the indexes in this object are not 0 based integers.

    So in order to loop you could enumerate all the properties that are defined for the object:

    $.ajax({
        url: '@Url.Action("LegalCheck")',
        type: 'POST',
        success: function (result) {
            for (var prop in result) {
                if (result.hasOwnProperty(prop)) {
                    // prop is the key and result[prop] is the legals array
                    var legals = result[prop];
    
                    alert('the key is ' + prop + ' and the value is ' + legals[0].Phrase);
                }
            }
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ASP.NET MVC application with action which should process posted XML data. At
I have an [HttpPost] action method signature like this: [HttpPost] public ActionResult Edit(ExistingPostViewModel model)
I have an ASP.NET MVC project with a form. In the Action method that
If I have an ASP.NET MVC controller action that is called from a jQuery
I have an action like this: public class News : System.Web.Mvc.Controller { public ActionResult
in my MVC application I have a controller (ProjectController) which has an action (create).
I have a MVC application which has a Controller that has a recursive method
On ASP.NET MVC 3, assume that we have following controller action: public ActionResult Index()
i have the following model method inside my asp.net MVc web application:- public IQueryable<User>
I have a MVC application which returns 2 types of Json responses from 2

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.