Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 780
  • 1.1k
  • 55.6k

Data Binding Fails

May 10 2024 9:17 PM

Hello Team,

Am trying to bind this tables in my controller so that I can update my data in my modal view but is not working, I put debugger in my javascript function which shows the room ID value has been selected but it doesn't push the data to my modal view.

  public JsonResult bindRoomForUpdate(int? RoomId)
        {
            var dataList = objHotelDbEntities.Rooms.Include("RoomType").Include("tblBookingStatus").ToList();
            var modifiedData = dataList.AsEnumerable().Where(a => a.RoomId == RoomId).Select(x => new RoomDetailViewModel
            {
                RoomId = x.RoomId,
                RoomNumber = x.RoomNumber,
                BookingStatusId = x.BookingStatusId,
                RoomTypeId = x.RoomType.RoomTypeId,
                RoomTypeName = x.RoomType.RoomTypeName,
                RoomCapacity = x.RoomCapacity,
                RoomDescription = x.RoomDescription,
                RoomPrice = x.RoomPrice,
                IsActive = x.IsActive
            }).FirstOrDefault();
            return Json(modifiedData, JsonRequestBehavior.AllowGet);
        }

Javascript function

  function bindRoomForUpdate($RoomId) {
        var objRoomViewModel = new Object();
        debugger
        $("#txtRoomId").val($RoomId);
        if ($RoomId != 0)
        {
            jQuery.ajax({
                url: '@Url.Action("bindRoomForUpdate", "Home")' + "?RoomId=" + $RoomId + "&ddbookingStatus=abc",
                data: JSON.stringify({
                    RoomId: $RoomId
                }),
                type:"Get",
                dataType: "JSON",
                contentType: "application/json, charset=utf-8",
                data: objRoomViewModel,
                success: function(objRoomViewModel) {
                    if (objRoomViewModel != null) {
                        debugger
                        $("#txtRoomId").val(objRoomViewModel.RoomId);
                        $("#txtroomNumber").val(objRoomViewModel.RoomNumber);
                        $("#ddroomType").val(objRoomViewModel.RoomTypeId);
                        $("#ddbookingStatus").val(objRoomViewModel.BookingStatusId);
                        $("#txtRoomCapacity").val(objRoomViewModel.RoomCapacity);
                        $("#txtRoomDescription").val(objRoomViewModel.RoomDescription);
                        $("#txtPrice").val(objRoomViewModel.RoomPrice);


                    }
                }
            });
        }
        else{
            $("#txtroomNumber").val('');
            $("#ddbookingStatus").val(1);
            $("#ddroomType").val(1);
            $("#txtRoomCapacity").val('');
            $("#txtRoomDescription").val('');
            $("#txtPrice").val('');
            $("#txtroomNumber").val('');
            $("#txtRoomId").val(0);
        }
        $("#exampleModal").modal("show");
        $("#btnSave").hide();
        $("#btnEdit").show();
    }
 


Answers (2)