How do I populate my Grid from a Partial View ajax call?
The Grid does not show up at all.
I'm using version15.3460.0.33
PartialView
@model IEnumerable
@(Html.EJ().Grid("TheGrid")
.Datasource((IEnumerable<object>)ViewBag.jobcards)
.Columns(col =>
{
col.Field("Id").HeaderText("The Id").Width(20).Add();
col.Field("SerialNumber").HeaderText("Serial Number").Width(60).Add();
col.Field("IsSelected").Type("checkbox").HeaderText("Selected").Width(20).Add();
})
)
@Html.EJ().ScriptManager()
View
@using (Html.BeginForm("CloseManufacturingJobs", "Jobcard", FormMethod.Post, new { @class = "form-horizontal", role = Model }))
{
@Html.AntiForgeryToken()
@Html.Label("Select Device", new { @class = "control-label" })
@if (@ViewBag.DeviceModels != null)
{
@Html.DropDownList("SelectedDevice", ViewBag.DeviceModels as IEnumerable, new { @class = "form-control", @id = "Devices" })
}
else
{
@Html.DropDownList("SelectedDevice", new SelectList(string.Empty, "Value", "Text"), new { @class = "form-control", @id = "Devices" })
}
Open Job Cards By Model
}
$(function () {
GetOpenJobcards();
$('#Devices').change(function () {
GetOpenJobcards();
});
});
function GetOpenJobcards() {
$.ajax({
type: "GET",
url: '@Url.Action("GetOpenJobcardsByModel", "Jobcard")',
data: { deviceModel: $('#Devices').val() },
success: function (data) {
$('#GridContainer').html(data);
//ej.widget.init($('#TheGrid'));
},
})
}
Ajax Method
[HttpGet]
public ActionResult GetOpenJobcardsByModel(string deviceModel)
{
IEnumerable jobcards = dbSatCom.JobCards.OrderByDescending(so => so.WeightFactor)
.Where(jc => jc.SerialNo.StartsWith(deviceModel) && jc.JobcardType == "M" && jc.Status == "O"
&& !jc.SerialNo.Contains("-E-") && !jc.SerialNo.StartsWith("CHE3-CH")).ToList().Select(jcvm => new JobcardViewModel
{
IsSelected = false,
SerialNumber = jcvm.SerialNo
}).OrderBy(x => x.SerialNumber).ToList();
ViewBag.datasource = jobcards;
return PartialView("_OpenJobcards");
}
I'm sure the rendering works because I use the Grid elsewhere, except I am not using a partial view in those instances.
Neill