I have a list of custom objects which is received by AJAX call's success function as follows.
$.ajax({
type: 'POST',
url: '@Url.Action("DeleteAdmin", "UserAdmin")',
cache: false,
dataType: 'json',
data: { userId: $('#hdnDeleteItem').val() },
success: function (data) {
if (data != null) {
$('#MainGrid').html(data.GridData); // this does not work
}
}
});
The WebGrid is as follows:
@grid.GetHtml(
htmlAttributes: new { id = "MainGrid", width = "700px" },
tableStyle: "table table-bordered table-responsive",
mode: WebGridPagerModes.All,
firstText: "<< First",
previousText: "< Prev",
nextText: "Next >",
lastText: "Last >>",
columns: grid.Columns(
grid.Column("UserId", "User ID"),
grid.Column("User Role", format: (item) => item.SelectedUserRole.UserRoleName),
grid.Column("Action",
format: @<text>
<a href="#" class="link-delete" id="@item.UserId" onclick="SetSelectedUserId(this)">Delete</a>
</text>)
)
)
Following is the action method that passes JSon result.
public JsonResult UpdateDetails()
{
IList<UserModel> userModels = GetUserModels();
return Json(new { GridData = userModels }, JsonRequestBehavior.AllowGet);
}
Though "data.GridData" in "success" function contains the list of objects passed by this method, it doesn't set them into WebGrid. Instead, the webgrid becomes invisible/empty.
Is there any way to set the list to WebGrid?