Knockout Binding Select Change with MVC 5
<p>I'm using Knockout's "foreach" function on my MVC application's model to load a table of dropdown options. When the selected dropdown value changes, I need to track that change in the model.</p>

<p>I tried using the subscribe option on the element in the model, but when it changes, the function I bound to it isn't firing. I'm aware there are several ways of implementing this change, but I'd prefer to stick with this format of defining my functions as shown at the bottom of the view.</p>

<p>Model:</p>

<pre><code>    public class ProfileLookAndFeelViewModel : StandardLayoutViewModel
        {
            public ProfileLookAndFeelViewModel()
            {
                Form = new FormGroup();
                PriceUOMDropdownOptions = new PriceUOM();
                UOMInformation = new UOMInformationGroup();
            }

            public FormGroup Form { get; set; }
            public PriceUOM PriceUOMDropdownOptions { get; set; }
            public UOMInformationGroup UOMInformation { get; set; }

            public class FormGroup
            {            
                public bool FormValueChanged { get; set; }            
            }

            public class PriceUOM
            {
                public int Id { get; set; }
                public String Name { get; set; }
                public string Code { get; set; }
            }

            public class PriceUOMOverride
            {
                public string ItemDescription { get; set; }
                public string TemplateCode { get; set; }
                public string UOMDesc { get; set; }
                public List&lt;PriceUOM&gt; PriceUOMDropdownOptions { get; set; }
                public int SelectedPriceUOM { get; set; }
                public int SelectedPriceUOMOriginal { get; set; }
                public bool SelectedPriceUOMChanged { get; set; }
            }  

            public class UOMInformationGroup
            {
                public UOMInformationGroup()
                {
                    UOMs = new List&lt;PriceUOMOverride&gt;();
                }

                public List&lt;PriceUOMOverride&gt; UOMs { get; set; }
                public bool UOMsChanged { get; set; }
            }
        }
</code></pre>

<p>View:</p>

<pre><code>    &lt;table class="table table-bordered table-hover table-striped"&gt;
        &lt;thead&gt;
            &lt;tr&gt;
                &lt;th&gt;Description&lt;/th&gt;
                &lt;th&gt;Template Code&lt;/th&gt;
                &lt;th&gt;Default UOM&lt;/th&gt;
            &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
            &lt;!-- ko foreach: $root.UOMInformation.UOMs --&gt;
            &lt;tr&gt;
                &lt;td data-bind="text: ItemDescription"&gt;&lt;/td&gt;
                &lt;td data-bind="text: TemplateCode"&gt;&lt;/td&gt;
                &lt;td class="center" &gt;
                    &lt;select data-bind="options: PriceUOMDropdownOptions, optionsText: 'Code', optionsValue: 'Id', value: SelectedPriceUOM, css: { important: SelectedPriceUOMChanged() == true }"&gt;&lt;/select&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;!-- /ko --&gt;
        &lt;/tbody&gt;
    &lt;/table&gt;  

    &lt;script type="text/javascript"&gt;
    $(function () {
        var vmProfileLookAndFeel = function () { var self = this; };
        vmProfileLookAndFeel = ko.mapping.childrenIndependently($.parseJSON('@Html.RawJsonForKoMapping(Model)'), ["UOMInformation", "Form", "PriceUOMDropdownOptions"]);
        vmProfileLookAndFeel.UOMInformation.UOMs.subscribe(function (newValue) {
            vmProfileLookAndFeel.ValueChanged();
        });

        vmProfileLookAndFeel.ValueChanged = function () {
            //Do something;
        };

        ko.applyBindings(vmProfileLookAndFeel);
        });
    &lt;/script&gt;
</code></pre>

<p>I tried this suggestion but answer here isn't loading data from a MVC model but a hard coded array</p>

<p><a href="https://stackoverflow.com/questions/16824234/subscribe-to-select-item-from-foreach-loop">Subscribe to select item from foreach loop</a></p>

<p><strong>EDIT:</strong></p>

<p>I updated the view to reflect adding the array as observable.</p>

<p>Here is the function that I call to map the objects</p>

<pre><code>    ko.mapping.childrenIndependently = function (jsObject, childrenArray) {
        var mapping = {
            "ignore": childrenArray
        }
        var vm = ko.mapping.fromJS(jsObject, mapping);

        // handle children
        for (var childrenArrayIndex = 0; childrenArrayIndex &lt; childrenArray.length; childrenArrayIndex++) {
            if (jsObject.hasOwnProperty(childrenArray[childrenArrayIndex])) {
                // if the property is an array, create an objservable array
                // and map each child
                // else map the property
                if ($.isArray(jsObject[childrenArray[childrenArrayIndex]])) {
                    vm[childrenArray[childrenArrayIndex]] = ko.observableArray();

                    for (var childObjectArrayIndex = 0; childObjectArrayIndex &lt; jsObject[childrenArray[childrenArrayIndex]].length; childObjectArrayIndex++) {
                        vm[childrenArray[childrenArrayIndex]].push(ko.mapping.childrenIndependently(jsObject[childrenArray[childrenArrayIndex]][childObjectArrayIndex], childrenArray.slice(childrenArrayIndex)));
                    }
                }
                else {
                    vm[childrenArray[childrenArrayIndex]] = ko.mapping.childrenIndependently(jsObject[childrenArray[childrenArrayIndex]], childrenArray.slice(childrenArrayIndex));
                }
            }
        }

        return vm;
    };
</code></pre>