title: Detecting Selected Row in html table Knockout/ASP.NET MVC
body: <p>I've loaded an ASP.NET MVC viewModel into KnockoutJS using ko.mapping.fromJS(Model).</p>
  
  <p>My viewModel looks something like this:</p>
  
  <pre><code>public IEnumerable&lt;FunkyThing&gt;funkyThings;
  public FunkyThing selectedFunkyThing;
  </code></pre>
  
  <p>I've then got in my HTML View a table which looks something like this</p>
  
  <pre><code>&lt;tbody data-bind="foreach: funkyThings"&gt;
      &lt;tr&gt;
          &lt;td data-bind="text:name"&gt;&lt;/td&gt;  
          &lt;td data-bind="text:funkiness"&gt;&lt;/td&gt;  
          &lt;td&gt;&lt;a href='#' title="Select Funky Thing" data-bind="click: $root.selectFunkyThing"&gt;&lt;/a&gt;
         &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>and all is good with this table.  Clicking the select funky thing link happily calls the selectFunkyThing function:</p>
  
  <pre><code>    model.selectFunkyThing= function (funkyThing) {
          window.location = '@Url.Action(MVC.FunkyThingController.Index())' + "?funkyThingID=" + funkyThing.funkyThingID();
  
      };
  </code></pre>
  
  <p>which in turn refreshes the page.  The MVC viewmodels is reloaded and selectedFunkyThing is populated with the selected FunkyThing and the knockout view models are then re-read from the MVC viewmodel.  So far so good.</p>
  
  <p>I then wanted to update the table to highlight the selected entry.
  So I updated the tr line as follows:</p>
  
  <pre><code>&lt;tr data-bind="css:{'selected': $root.isSelected()}"&gt;
  </code></pre>
  
  <p>and created the new knockout function:</p>
  
  <pre><code> model.isSelected = function (funkyThing) {
              return funkyThing.funkyThingID== model.selectedFunkyThing.funkyThingID;
  
          };
  </code></pre>
  
  <p>but... it's not working.
  Chrome throws a javascript exception stating that the FunkyThing parameter is undefined.
  Technically I figure I could solve it by changing the MVC viewModel to actually set a isSelected on each FunkyThing within the array.  However I figure there's got to be away of doing this from Knockout?</p>