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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:11:08+00:00 2026-05-22T21:11:08+00:00

I have a viewModel with an array of answerGroup objects. When the feedback property

  • 0

I have a viewModel with an array of answerGroup objects. When the feedback property of one of the answerGroup objects is updated I want to save the updated object to my database by passing it via ajax to my ASP.Net MVC app.

Instead of having a typical save button or link, I want the object to be passed to the Ajax call when the object’s property has been updated. I thought I could do this by binding to the change event of the textarea element but if I do this the ajax function is called but the underlying answerGroup object’s feedback property is not updated.

I’m using Knockout 1.2.1. Below is the JavaScript code, I haven’t included the HTML.

Am I going about this the wrong way or is it just that my syntax for the knockout.js event binding is incorrect?

<script>
var viewModel = {}

$(function () {
    viewModel.scenarioId = ko.observable($("#Scenario_ScenarioID").val());
    viewModel.answerGroups = ko.observableArray([]);
    viewModel.addGroup = function (answerGroup) {

        // add item to beginning of array
        this.answerGroups.unshift(answerGroup);
    };

    ko.applyBindings(viewModel);
});

function answerGroup() {
    this.id = ko.observable();
    this.name = ko.observable();
    this.feedback = ko.observable();

    // the groups feedback has been updated so save
    // these details back to the server
    this.updateGroup = function (event) {

      // javascript api library that is an ajax function.
      // this works without a problem.
      api.updateAnswerGroup({
        success: function (result) {
            alert("saved!");
        },
        error: function (e) {
           alert("error!");
        },
        data: "answerGroupId=" + this.id + "&feedback=" + this.feedback
      });

      return true;
    };
}
</script>

<script id="answerGroupsTemplate" type="text/html">
  <div>
    <h4><a href='#'>${ $data.name }</h4>
    <div>
       <textarea cols="100" rows="2" data-bind="event: { text: feedback, change: updateGroup }">
       </textarea>                  
    </div>
  </div>
</script>
  • 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-22T21:11:09+00:00Added an answer on May 22, 2026 at 9:11 pm

    The typical way to handle this in Knockout is to do a manual subscription on the observable that you want to react to changes on.

    So, you would do something like:

    function answerGroup() {
        this.id = ko.observable();
        this.name = ko.observable();
        this.feedback = ko.observable();
    
        this.feedback.subscribe(function (newValue) {
           //run your update code here
        }, this);
    }
    

    The second parameter to the subscribe function controls the context (“this”) when the function runs.

    The nice part about a subscription like this is that it will fire when the observable is changed programmatically or changed based on a binding in your UI.

    Brief docs on it here: http://knockoutjs.com/documentation/observables.html#explicitly-subscribing-to-observables

    I had a post that included info on using manual subscriptions here too.

    Hope this helps.

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

Sidebar

Related Questions

I have a ViewModel which exposes the string property PageToolBarVisible which can be true
I have a TextBox.TextProperty bound to a ViewModel property. In the binding I have
I have the following validation method in my viewmodel (example is showing only one
I have a viewModel with an observableArray that gets updated from the server, then
I have a ViewModel class which i want to respond to the built in
I have one ViewModel for enums handling (few entities in Entity Framework). 1) Philosophically,
I have a ViewModel with a property as below: [DisplayName(As Configured On:)] [DisplayFormat(DataFormatString={0:d}, ApplyFormatInEditMode=true)]
I am hoping this is an easy one. In my viewmodel I have an
I Have an Array of users that i want to pass into a view
I Have a controller that returns a viewModel. That viewModel has a property called

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.