简体   繁体   English

mvc telerik 网格中的网格操作

[英]grid operation in mvc telerik grid

how to perform the edit and delete operations in grid如何在网格中执行编辑和删除操作

i have the following grid我有以下网格

<%=Html.Telerik().Grid(Model).Name("Grid").Columns(columns =>
    {

        columns.Bound(m => m.Keywords);
        columns.Bound(m => m.Country).Title("Location");
        columns.Bound(m => m.AreaID);
        columns.Bound(m => m.JobSearchAgentID).Hidden(false);

    }).DataBinding(databinding =>
        {
            databinding.Server().Select("Agentlist", "Grid", new
            {
                ajax = ViewData["ajax"]
            });
            databinding.Ajax().Select("Agentlist",
               "Grid").Enabled((bool)ViewData["ajax"]);
        })
               .DataKeys(keys =>
                   {
                       keys.Add(m => m.JobSearchAgentID);
                   }
                   )
        .Scrollable(scrolling => scrolling.Enabled((bool)ViewData["scrolling"]))
        .Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
        .Pageable(paging => paging.Enabled((bool)ViewData["paging"]))
        .Filterable(filtering => filtering.Enabled((bool)ViewData["filtering"]))
        .Groupable(grouping => grouping.Enabled((bool)ViewData["grouping"]))
        .Footer((bool)ViewData["showFooter"])


           %>
      <%}%>

Everything you need about Telerik MVC Grid Control您需要的关于 Telerik MVC 网格控制的一切

http://demos.telerik.com/aspnet-mvc/grid/editingajax dead link http://demos.telerik.com/aspnet-mvc/grid/editingajax 死链接

http://demos.telerik.com/aspnet-mvc/grid http://demos.telerik.com/aspnet-mvc/grid

Here's an example of a grid that allows add and edit within the grid:这是一个允许在网格内添加和编辑的网格示例:

<% Html.Telerik().Grid<ReportingPeriodGroupDto>()
    .Name("ReportingPeriodGroupAdminGrid")
    .DataKeys(keys => keys.Add(o => o.Id))
    .Editable(editing => editing.Mode(GridEditMode.InLine))
    .ToolBar(commands =>
    {
        commands.Insert();
    })
    .DataBinding(dataBinding => dataBinding.Ajax()
            .Select("SelectReportingPeriodGroup", "Admin")
            .Insert("InsertReportingPeriodGroup", "Admin")
            .Update("UpdateReportingPeriodGroup", "Admin")
    )
    .Columns(columns =>
    {
        columns.Bound(o => o.ShortDescription).Width("10em").Width("8em");
        columns.Bound(o => o.LongDescription).Width("20em");
        columns.Command(commands => commands.Edit()).Title("Actions");
    })
    .Footer(false)
    .Render();
%>

NOTE: You must add these Insert and Update methods to your controller注意:您必须将这些插入和更新方法添加到 controller

[AcceptVerbs(HttpVerbs.Post)]
[GridAction(GridName = "ReportingPeriodGroupAdminGrid")]
public ActionResult InsertReportingPeriodGroup()
{
    ReportingPeriodGroupDto reportingPeriodGroupDto = new ReportingPeriodGroupDto();
    TryUpdateModel(reportingPeriodGroupDto);
    if (ModelState.IsValid)
    {
        reportingPeriodGroupDto.CreatedBy = UserId;
        reportingPeriodGroupDto.CreatedDate = DateTime.Now.ToString();
        ITransformer transformer = ServiceFinder.Instance.ServiceFactory.RedPortalTransformerFactory.GetTransformer(reportingPeriodGroupDto.GetType());
        ReportingPeriodGroup parent = (ReportingPeriodGroup)transformer.Transform(reportingPeriodGroupDto);
        RedPortalDbContext.ReportingPeriodGroups.Add(parent);
        RedPortalDbContext.SaveChanges();
    }
    return SelectReportingPeriodGroup();
}

[AcceptVerbs(HttpVerbs.Post)]
[GridAction(GridName = "ReportingPeriodGroupAdminGrid")]
public ActionResult UpdateReportingPeriodGroup()
{
    ReportingPeriodGroupDto reportingPeriodGroupDto = new ReportingPeriodGroupDto();
    if (TryUpdateModel(reportingPeriodGroupDto))
    {
        reportingPeriodGroupDto.UpdatedBy = UserId;
        reportingPeriodGroupDto.UpdatedDate = DateTime.Now.ToString();
        ITransformer transformer = ServiceFinder.Instance.ServiceFactory.RedPortalTransformerFactory.GetTransformer(reportingPeriodGroupDto.GetType());
        ReportingPeriodGroup parent = (ReportingPeriodGroup)transformer.Transform(reportingPeriodGroupDto);
        RedPortalDbContext.ReportingPeriodGroups.Add(parent);
        RedPortalDbContext.Entry(parent).State = EntityState.Modified;
        RedPortalDbContext.SaveChanges();
    }
    return SelectReportingPeriodGroup();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM