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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:19:24+00:00 2026-05-24T06:19:24+00:00

I am doing an AJAX call to a controller method on my ASP.Net MVC

  • 0

I am doing an AJAX call to a controller method on my ASP.Net MVC web site. That method is sending back some custom objects JSONized.

I’m having trouble treating lists from these C# objects as Javascript arrays and I’m just new enough to Javascript not to understand what the problem is.

I have an object called Animations. Each Animation has a List named Frames. If I try to pass the JSONized Frames e.g. currentAnimation.Frames to a Javascript method expecting an array of integers I don’t get an exception but the receiving method doesn’t get an array of integers like it expects so it also doesn’t do anything with the data.

Here is my Javascript. Notice it passes “this.spriteSheet.Animations[sheet].Frames” to the “addAnim” method. This doesn’t work.

for (var sheet in this.spriteSheet.Animations) {

    var animation = this.addAnim(this.spriteSheet.Animations[sheet].Name, this.spriteSheet.Animations[sheet].Speed, this.spriteSheet.Animations[sheet].Frames);

    if (this.flip) {
        animation.flip.x = true; ;
    }
}

And here is some Javascript I modified to work (although I don’t know if it’s the best solution and I still don’t really know what the problem is):

for (var sheet in this.spriteSheet.Animations) {

        var frames = new Array();

        for (var frame in this.spriteSheet.Animations[sheet].Frames) {
            frames[frame] = this.spriteSheet.Animations[sheet].Frames[frame];
        }

    var animation = this.addAnim(this.spriteSheet.Animations[sheet].Name, this.spriteSheet.Animations[sheet].Speed, frames);

    if (this.flip) {
        animation.flip.x = true; ;
    }
}

Here is my controller action code:

[AcceptVerbs(HttpVerbs.Get)]
public ActionResult GetPlay(int id)
{
    // get the game that has been requested
    Cherub.Common.Logic.Game game = new Common.Logic.Game();

    // get the play data
    Play play = game.GetPlay(id);

    return Json(play, JsonRequestBehavior.AllowGet);
}

I am calling the controller action with JQuery’s ajax call:

$.ajax({
        type: "GET",
        url: ajaxUrl,
        contentType: "application/json; charset=utf-8",
        data: {},
        dataType: "json",
        success: functionSuccess,
        error: functionFailure,
        cache: false
    });

Here’s a small section of the JSON coming back from the controller action:

"Animations":[{"Name":"bob","Frames":[0,1,2],"Speed":0.2}]

Here’s my SpriteSheet class

public class SpriteSheet
{
    public SpriteSheet(string name)
    {
        Animations = new List<Animation>();

        switch(name.ToLower())
        {
            case "sylph":
                Sheet = "media/Sylph.png";
                Animations.Add(new Animation { Name = "bob", Frames = new List<int> { 0, 1, 2 }, Speed = .2f });
                FrameSize = new Vector2D { X = 94, Y = 125 };
                break;
        }
    }

    public string Sheet { get; set; }
    public List<Animation> Animations { get; set; }
    public Vector2D FrameSize { get; set; }
}

public class Animation
{
    public string Name { get; set; }
    public List<int> Frames { get; set; }
    public float Speed { get; set; }
}
  • 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-24T06:19:26+00:00Added an answer on May 24, 2026 at 6:19 am

    Based on the sample in your question, Animations and Frames are arrays – but you’re treating them like they are objects.

    for..in loops are useful for iterating over the properties of an object, but you need to loop through each element in the array using a simple for loop instead.

    If you change your for .. in loops, you should get the result you’re looking for:

    var anims = spriteSheet.SpriteSheet.Animations;
    
    for(i = 0; i < anims.length; i++) {
    
        var frames = new Array();
        for(j = 0; j < anims[i].Frames.length; j++) {
    
            frames[i] = anims[i].Frames[j];
    
            ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an ASP.Net mvc application which has a requirement to do some small,
I am doing a web site using spring mvc framework. I want to do
Im doing an ajax call, that does the following on success: success: function(data) {
I am working on an MVC site that is the first my company has
I am doing Ajax call using jQuery and my URL is like http://localhost;3327/DummyAps/Demo.aspx In
I am doing a simple ajax call with the YahooUI Javascript library as follows:
I want to include an AJAX call within a .submit() handler so that I
I'm trying to send some data via JQuery ajax to a grails controller Here's
I am at an ASP.NET MVC page located at the following address: http://somedomain/someapp/Foo/Bar?param=val I
I use this AJAX to call my Excel Export action on the controller: $(#ExportToExcel).click(function

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.