Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use IEnumerable<ExpandoObject> in knockout.js?
    text
    copied!<p><strong>Problem Description</strong></p> <p>I wanted to ask about how to use a list Exbando Objects in knockout.js,am using Rob Conrey's Massive and all returned results are dynamic, that's fine with me it suits my needs but when it comes to sending results to knockout i just don't know what to do with it.</p> <p><strong>Goal</strong></p> <p>Access object properties like obj.Name, obj.Brand etc...</p> <p><strong>Sample Code</strong></p> <p><em>View:</em></p> <pre><code>&lt;div data-bind="foreach: Products"&gt; &lt;p&gt;Product name: &lt;strong data-bind="text: Name"&gt;&lt;/strong&gt;&lt;/p&gt; &lt;/div&gt; </code></pre> <p><em>Controller:</em></p> <pre><code>public JsonResult GetProducts() { Products products = new Products(); var Model = products.GetAllProducts(); return Json(Model, JsonRequestBehavior.AllowGet); } </code></pre> <p>The result of calling GetProducts is:</p> <blockquote> <p>[[{"Key":"Id","Value":1},{"Key":"Name","Value":"Badass Boots"},{"Key":"Brand","Value":"Nike"},{"Key":"Description","Value":"Super cool boots that can make you fly (Not Really!)."}, etc...]]</p> </blockquote> <p><em>Script File:</em></p> <pre><code>function ProductListViewModel() { // Data var self = this; self.Products = ko.observableArray([]); $.getJSON("/Home/GetProducts", function (data) { self.Products(data); }); } </code></pre> <p>JavaScript error on running the application:</p> <blockquote> <p>Uncaught ReferenceError: Unable to parse bindings. Bindings value: text: Name Message: Name is not defined</p> </blockquote> <p><strong>Screen Shot 1:</strong></p> <p><img src="https://i.stack.imgur.com/zAbrs.png" alt="enter image description here"></p> <p><strong>Screen Shot 2:</strong></p> <p><img src="https://i.stack.imgur.com/OPYHs.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload