假设我的cshtml中有以下网格
@(Html.Kendo().Grid<Accessibility.Models.CompanyModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.Name);
columns.Bound(c => c.Description);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Sortable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.Id))
.Create(update => update.Action("Company", "Company"))
.Read(read => read.Action("GetCompanies", "Company"))
.Update(update => update.Action("Company", "Company"))
.Destroy(update => update.Action("DestroyCompany", "Company"))
)
)
如何以编程方式创建上述网格,而不是在我的cshtml文件中对其进行硬编码?
答案 0 :(得分:1)
根据您的评论,我建议创建一个包含网格标记的局部视图,然后在控制器中根据用户的输入水合模型,然后返回局部视图和模型。例如,
public ActionResult GetCompanies(int companyId)
{
CompanyModel model = GetCompanies(companyId);
return PartialView("_CompaniesGrid", model);
}