Click here to Skip to main content
15,886,030 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
This is table In Html
HTML
<table style="width:100%" class="table table-striped">

        <tr>
            <th></th>
            @foreach (var facilityCategory in Model.FacilityCategory)
            {
                <th>
                    @facilityCategory.Name.ToString()
                </th>

            }
        </tr>
        @{
            string dynamicblockdate = "";
            foreach (var facilityCategory in Model.FacilityCategory)

            {
                string beds = "";
                foreach (var facility in Model.Facility.Where(x => x.FacilityCategoryId == facilityCategory.Id))
                {
                    beds += "<br>" +
                            "<input type='checkbox' id='checkbox' facility-id='" + facility.Id+"' name='checkbox' class='block-date style-data' style='text-align:right;' />"+
                            " " +
                            facility.Name;
                }
                dynamicblockdate += "<td class='data-Block-Date' data-facilityCategory-id='" + facilityCategory.Id + "'>"+
                                Html.Raw(beds)+
                                "</td>";
            }
        }
        @foreach (var timeSlot in Model.TimeSlot)
        {
            <tr class="data-timeSlot" data-timeSlot-id="@timeSlot.Id">
                <td width="150px">
                @timeSlot.Name.ToString()
                </td>
                    @Html.Raw(dynamicblockdate)
            </tr>
        }
    </table>



JavaScript
$('.data-timeSlot').each(function (index, timeslot) //------timeslot
       {
           $(timeslot).find('.data-Block-Date').each(function (index2, facilityCategory) //---Search Facilitycategoty from timeslot th
           {
               $(facilityCategory).find('.block-date').each(function (index3, facility) //--Find facility beds
               {
                   if ($(facilityCategory).find('.block-date').prop('checked')) {
                       var facilityBlockDate = {};
                       facilityBlockDate.FacilityCategoryId = $(facilityCategory).attr('data-facilityCategory-id');
                       facilityBlockDate.TimeSlotId = $(timeslot).attr('data-timeSlot-id');
                       facilityBlockDate.FacilityId = $(facility).attr('facility-id'); //--Beds id get
                       facilityBlockDate.IsBlock = $(facilityCategory).find('.block-date').prop('checked');
                       facilityBlockDate.From = $('#From').val();
                       facilityBlockDate.To = $('#To').val();
                       facilityBlockDate.Remark = $('#Remark').val();
                       selectedfacilityBlockDate.push(facilityBlockDate);

                   }
               });
           });
       });


What I have tried:

I need to have only two beds in the database. when clicking two check boxes in the relevant facility category all beds are saved. I want only save 2 beds. How to do it from Ajax.
In My code all facility beds are save when check on check box. I want to save only two beds.. Here is my codes...
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900