1

In my View I have a grid and a checkbox above the grid. On checking the check box I am unable to refresh the grid. I am using Grid.MVC. Can someone help me on this.

Index.cshtml


@(Html.Grid(Model.RequestDetail).Named("RequestGrid").Columns(columns =>
{
    columns.Add(c => c.RequestNumber).Titled("Request Number").Sanitized(false).Encoded(false).RenderValueAs(o => Html.ActionLink(o.RequestNumber, "", new { requestNumber = o.RequestNumber }, new { @class = "anchorDetail" }).ToHtmlString());
    columns.Add(c => c.RequestType).Titled("Request Type");
    columns.Add(c => c.RequestedBy).Titled("Requested By");
    columns.Add(c => c.CreatedDate).Titled("Created").Format("{0:d-MMM-yyyy}");
    columns.Add(c => c.AssignedTo).Titled("Assigned To");
    columns.Add(c => c.DueDate).Titled("Due Date").Format("{0:d-MMM-yyyy}");
    columns.Add(c => c.RequestStatus).Titled("Request Status");
    columns.Add(c => c.CompletedDate).Titled("Completed Date").Format("{0:d-MMM-yyyy}");
}).WithPaging(10).Sortable())

Script:

function ViewAssignedRequests() {
            var userName = "@ViewData["Name"]";
            var isChecked;
            if (document.getElementById('chkAssign').checked) {
                isChecked = true;
            }
            else {
                isChecked = false;
            }
            $.ajax({
                type: "POST",
                url: "/ViewRequestDetails/GetAssignedList",
                contentType: "application/json; charset=utf-8",
                data: "{ 'userName' : '" + userName + "', 'isChecked' : '" + isChecked + "' }",
                datatype: "json",
                success: function () {
                    $('.grid-mvc').gridmvc();
                    $('#RequestGrid').reload();
                    //pageGrids.RequestGrid.refreshFullGrid();
                },
                error: function () {
                    alert("Dynamic content load failed.");
                }
            });
        }

My controller is directly returning the entire view

[HttpPost]
        public ActionResult GetAssignedList(string userName, bool isChecked)
        {
            RequestDetails reqObj = new RequestDetails();
            reqObj.RequestDetail = viewDAObj.PopulateRequestAssignedGrid(userName, isChecked);
            return View("Index", reqObj);
        }
M_Jero
  • 39
  • 2
  • 10
  • Your calling `.reload()` but you have not assigned any new data to the grid so it just display the same results. –  Dec 19 '17 at 07:02
  • But my controller Post Method is returning the View. So how do I assign data again. – M_Jero Dec 19 '17 at 07:23
  • You have not shown your controller method! And you do not do anything with the html that it returns. But it would make no sense to return a view unless you were returning a partial containing a new `Html.Grid()` and then replace the existing one (in which case refreshing the existing one would be pointless since it no longer exists) –  Dec 19 '17 at 07:26

0 Answers0