I have been trying for a few days now with no luck. I'm building a ASP.NET MVC 5 application. I'm building a reservations application for a restaurant. The idea is to extract a days reservations group it by location with linq to entities and then send it with signalR to the client side. On the client side I want to bind this grouped query with knockout.js and then display it, and that is where everything goes wrong. Sending the grouped reservations to the client side works fine but I can't seem to make the mapping with knockout work. Please help.
Model on Server Side
var Reservations = db.BistroReservations_Reservations
.GroupBy(reservation => reservation.BistroReservations_Location.Description)
.OrderBy(reservation => reservation.Key.ToString()).ToList();
var context = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext<ReservationsHub>();
context.Clients.All.TestingGroupedReservations(Reservations);
Model on Client Side
var ReservationsViewModel = function () {
var self = this;
var connection = $.hubConnection();
var hub = connection.createHubProxy('reservationsHub')
var GroupedReservations = ko.mapping.fromJS(reservations);
//Testing -map a collection object to a observalbe and display it underneath the webpage
hub.on('TestingGroupedReservations', function (reservation) {
ko.mapping.fromJS(reservation, GroupedReservations);
});
}
ko.applyBindings(new ReservationsViewModel());
Code on the client view side
<table class="table" data-bind="visible: !loading()">
<thead class=".h1 glyphicon-bold">Reservations of Selected Day</thead>
<tbody data-bind="foreach: GroupedReservations">
<tr>
<td>Shift</td>
<td>
<table data-bind="foreach:$data">
<tbody>
<tr>
<td data-bind="text:BistroReservations_GuestID"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>