Controller Code:
public string getJSON() { Product _objProduct = new Product(); DataTable _objDT = _objProduct.getProduct(); System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); Dictionary<string, object> row = null; foreach (DataRow dr in _objDT.Rows) { row = new Dictionary<string, object>(); foreach (DataColumn col in _objDT.Columns) { row.Add(col.ColumnName, dr[col]); } rows.Add(row); } return serializer.Serialize(rows); }
View Code
<script> $(document).ready(function () { $('#divheader').append("<h2>Please place an order</h2>"); $.ajax({ type: "Post", url: "/Order/getJSON", data: {}, success: function (data) { alert(data); /*function ReservationsViewModel() { var self = this; self.product = data; self.addOrder = function () { alert('in'); self.order.push(new orderReservation(_objModel)); } } ko.applyBindings(new ReservationsViewModel());*/ } }); }); </script> <table> <thead> <tr> <th>Product Name</th> <th>Quantity/Unit</th> <th>Unit Price</th> <th>Quanitity</th> </tr> </thead> <tbody> <tr> <td> <select id="ddlProduct"></select> </td> <td><label></label></td> <td><label></label></td> </tr> </tbody> </table>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)