any suggestion is welcome…JSON Response – one substring not being recognized by my code

This is code that has been gleaned from "inline editing of the web grid" at
www.mikesdotnetting.com

All code below works, the drop downs are properly populated, the grid displays as it should, the EDIT and SAVE work, the JSON write to CreateCalendarF works, the code inside there correctly changes the db, and the code there responds with the JSON string
exactly as I want it to.

The problem is that the calWId/WeekSelectionCal column in grid row that was updated does not reflect the change that was send over with the JSON response.  After I refresh the page it shows it correctly. All the other changes are being recognized

My problem is related to self inflicted confusion caused by different names for the same thing in two tables in the db.

calRecords  calr which is the main table  uses calWId

TimeSelections ts is the table that is being joined on JOIN TimeSelections ts ON calr.calWId = ts.WeekSelectionId

The last piece of code below is the JSON response retrieved from the Response in the browser.

<script>
    $(function () {

        $('.edit-mode').hide();
        $('.edit-calendar').on('click', function () {
            var tr = $(this).parents('tr:first');
            tr.find('.edit-mode, .display-mode').toggle();
        });
        $('.save-calendar').on('click', function () {
            var tr = $(this).parents('tr:first');
            var ownerlocationid = $(this).prop('id');
            var location = tr.find('Location').val();
            var calwid = tr.find('#calWId').val();
            var caldid = tr.find('#calDId').val();
            var caloid = tr.find('#calOId').val();
            var qty = tr.find('#Qty').val();
            var c12 = tr.find('#C12').val();
            var c11 = tr.find('#C11').val();
            var c10 = tr.find('#C10').val();
            var c9 = tr.find('#C9').val();
            var c8 = tr.find('#C8').val();
            var c7 = tr.find('#C7').val();
            var c6 = tr.find('#C6').val();
            var c5 = tr.find('#C5').val();
            var c5min = tr.find('#C5min').val();
            var isactive = tr.find('#isActive').is(':checked');
            $.post(
                    '/Methods/CreateCalendarF',
                    { OwnerLocationId: ownerlocationid, Location: location, calWId: calwid, calDId: caldid, calOId: caloid, C12: c12, C11: c11, C10: c10, C9: c9, C8: c8, C7: c7, C6: c6, C5: c5, C5min: c5min, isActive: isactive },
                    function (cal) {
                        tr.find('#location').text(cal.Location);
                        tr.find('#weekselectioncal').text(cal.WeekSelectionCal);
                        tr.find('#calday').text(cal.calDay);
                        tr.find('#calorder').text(cal.calOrder);
                        tr.find('#qty').text(cal.Qty);
                        tr.find('#c12').text(cal.C12);
                        tr.find('#c11').text(cal.C11);
                        tr.find('#c10').text(cal.C10);
                        tr.find('#c9').text(cal.C9);
                        tr.find('#c8').text(cal.C8);
                        tr.find('#c7').text(cal.C7);
                        tr.find('#c6').text(cal.C6);
                        tr.find('#c5').text(cal.C5);
                        tr.find('#c5min').text(cal.C5min);
                        tr.find('#isactive-display').removeAttr("disabled").attr('checked', cal.isActive).attr('disabled', true);
                    }, "json");
            tr.find('.edit-mode, .display-mode').toggle();
            $('.edit-mode').val('0');
        });
    })
</script>

grid.Column("Week", style: "col3", format:
                    @<text>
                    <span id="calweek" class="display-mode">@item.WeekSelectionCal</span>
                    @Html.DropDownList("calWId", null, weekselections, item.calWId, new { @class = "edit-mode" })
                    </text>),

var weekselections = db.Query("SELECT TOP (4) WeekSelectionId, WeekSelectionCal FROM TimeSelections")
        .Select(weekselection => new SelectListItem
            {
            Value = weekselection.WeekSelectionId.ToString(),
            Text = weekselection.WeekSelectionCal
            });

{"ownerLocationId":61,"Location":"JStables","WeekSelectionCal":"tbd","calDay":"tbd","calOrder":"tbd","Qty":3,"isActive":false,"C12":2,"C11":0,"C10":0,"C9":0,"C8":0,"C7":0,"C6":0,"C5":0,"C5min":1} 

Leave a Reply