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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:50:01+00:00 2026-06-18T04:50:01+00:00

I have been using knockout.js for a while now, and haven’t encountered this problem

  • 0

I have been using knockout.js for a while now, and haven’t encountered this problem before. Usually, when I try to push a new js object to an observableArray, it works without an issue, but for some reason, this time around I’m getting this error:

TypeError: self.Students.push is not a function

Here is a snippet of my code:

window.ApiClient = {
    ServiceUrl: "/api/students",

    Start: function () {
        var viewModel = ApiClient.ViewModel(ngon.ClientViewModel);
        ko.applyBindings(viewModel);                
        viewModel.get();
    }    
};

ApiClient.ViewModel = function(data) {
    var self = this;
    ko.mapping.fromJS(data, {}, this);    

    this.get = function (id) {
        if (id == undefined) {
            return ApiClient.Service.get(self.PageSize(), self.PageNumber(), function (data) {
                self.Students(data);
            });
        }
    }

    this.post = function () {        
        return ApiClient.Service.post(self.DetailedStudent, function (data) {                        
            self.Students.push(data);
        });
    }

    return this;
}

ApiClient.Service = function () {    
    var _get = function (pageSize, pageNumber, callback) {
        sv.shouldShowLoading = false;
        var queryParams = String.format("?pageSize={0}&pageNumber={1}", pageSize, pageNumber);        
        $.ajax(ApiClient.ServiceUrl + queryParams, {
            dataType: "json",
            type: "get",
            success: callback
        });
    }

    var _post = function (student, callback) {
        $.ajax(ApiClient.ServiceUrl, {
            data: ko.mapping.toJSON(student),
            type: "post",
            contentType: "application/json; charset-utf-8",
            statusCode: {
                201 /*Created*/: callback,
                400 /*BadRequest*/: function (jqxhr) {
                    var validationResult = $.parseJSON(jqxhr.responseText);
                    alert(jqxhr.responseText);
                }
            }
        });
    }

    return {        
        get: _get, 
        post: _post
    };
}();

$(document).ready(function () {    
    ApiClient.Start();      
});

My student object is a very simple C# object that has Id, FirstName, LastName. The get() function works without any issues, it’s just the callback function from the post() that cannot push the resulting data. Also, the data being returned back from the server looks correct:

{"Id":"rea","FirstName":"asdf","MiddleName":null,"LastName":"rrr"}
  • 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-18T04:50:02+00:00Added an answer on June 18, 2026 at 4:50 am

    I solved this! It’s because the initial viewModel, when being instantiated by the page’s view model object had ‘null’ for its Students property.

    knockout.js requires non-null values for all fields that are to be auto mapped.

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

Sidebar

Related Questions

Hi; i try to learn knockout.js using asp.net mvc razor. i have been written
I have been using the following line of code happily for a while now
We have been using Visual Studio Database projects for a while now and they
I have been using Bootstrap for a while now and love it. Saves me
I have been using C# for a while now, and going back to C++
I have been using an API to do some work. This is how I
I have been using OpenGL 4.X already for a while to write Windows applications.I
I have been using Apache on my local LAN. The problem is that i
We have been using SVN at my workplace for a few years now and
I have been using JIRA for the past 15 months, and now I find

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.