加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-3 – 最初未显示Telerik MVC Grid ClientTemplate复

发布时间:2020-12-16 06:29:44 所属栏目:asp.Net 来源:网络整理
导读:我对这里的帖子有一个非常类似的问题: Telerik grid with checkbox – Checkbox not showing up when the grid initially paints 基本上,我有一个带有ClientTemplate列的telerik MVC3剃刀网格,该列包含一个复选框.当页面最初加载时,复选框不在那里 – 而是
我对这里的帖子有一个非常类似的问题:
Telerik grid with checkbox – Checkbox not showing up when the grid initially paints

基本上,我有一个带有ClientTemplate列的telerik MVC3剃刀网格,该列包含一个复选框.当页面最初加载时,复选框不在那里 – 而是我想要复选框的值.但是,当触发ajax(例如将列分组在一起)时,复选框显示没有问题.

我真的不明白我上面粘贴的线程的解决方案….所以也许这就是答案,我只是不知道如何调用网格的构造函数.这是我的代码:

research.cshtml

@(Html.Telerik().Grid(Model)
    .Name("Grid")
    .DataKeys(keys => keys.Add(m => m.MessageInformation.MessageGUID))
    .DataBinding(databinding => databinding.Ajax()
        .Select("_ViewMessages","Results")
        .Update("_UpdateSelectedMessage","Results"))
    .Columns(columns =>
                 {
                     columns.Bound(o => o.MessageInformation.MessageGUID)
                         .ClientTemplate("<input type='checkbox' id='chkMessage' name='checkedRecords' value='<#= MessageInformation.MessageGUID #>' />")
                         .Title("Check")
                         .Width(50)
                         .HtmlAttributes(new { style = "text-align:center" });
                     columns.Bound(o => o.MessageInformation.MessageGUID).Title("ID");
                     columns.Bound(o => o.MessageInformation.MessageReceivedDateTime).Title("Received Date").Format("{0:d}");
                     columns.Bound(o => o.MessageInformation.MessageReceivedDateTime).Title("Received Time").Format("{0:t}");
                     columns.Bound(o => o.MessageInformation.MedVAMessageTypeString).Title("Message Type");
                     columns.Bound(o => o.MessageStatus).Title("Status");
                     columns.Command(commands => commands.Edit().ButtonType(GridButtonType.Text)).Title("Edit");
                 })

    .Editable(editing => editing.Mode(GridEditMode.PopUp))
    .Scrollable(scrolling => scrolling.Enabled(true))
    .Sortable(sorting => sorting.Enabled(true))
    .Pageable(paging => paging.Enabled(true))
    .Filterable(filtering => filtering.Enabled(true))
    .Groupable(grouping => grouping.Enabled(true))
    .Footer(true)
    )

ResultsController.cs

[GridAction]
        public ActionResult Research()
        {
            ViewBag.Message = "Research";

            return View(DataAccess.Get_Messages());
        }

        [GridAction]
        public ActionResult _ViewMessages()
        {
            ViewBag.Message = "Research";

            return View(new GridModel(DataAccess.Get_Messages()));
        }

解决方法

您最初绑定到服务器数据,因此您将需要服务器模板以及客户端模板:

@(Html.Telerik().Grid(Model)
    .Name("Grid")
    .DataKeys(keys => keys.Add(m => m.MessageInformation.MessageGUID))
    .DataBinding(databinding => databinding.Ajax()
        .Select("_ViewMessages","Results"))
    .Columns(columns =>
                 {
                     columns.Bound(o => o.MessageInformation.MessageGUID)
                         .Template(mi => {
                             %>
                                 <input type='checkbox' id='chkMessage' name='checkedRecords' value='<%= mi.MessageGUID %>' />
                             %>
                         })
                         .ClientTemplate("<input type='checkbox' id='chkMessage' name='checkedRecords' value='<#= MessageInformation.MessageGUID #>' />")
                         .Title("Check")
                         .Width(50)
                         .HtmlAttributes(new { style = "text-align:center" });
                     columns.Bound(o => o.MessageInformation.MessageGUID).Title("ID");
                     columns.Bound(o => o.MessageInformation.MessageReceivedDateTime).Title("Received Date").Format("{0:d}");
                     columns.Bound(o => o.MessageInformation.MessageReceivedDateTime).Title("Received Time").Format("{0:t}");
                     columns.Bound(o => o.MessageInformation.MedVAMessageTypeString).Title("Message Type");
                     columns.Bound(o => o.MessageStatus).Title("Status");
                     columns.Command(commands => commands.Edit().ButtonType(GridButtonType.Text)).Title("Edit");
                 })

    .Editable(editing => editing.Mode(GridEditMode.PopUp))
    .Scrollable(scrolling => scrolling.Enabled(true))
    .Sortable(sorting => sorting.Enabled(true))
    .Pageable(paging => paging.Enabled(true))
    .Filterable(filtering => filtering.Enabled(true))
    .Groupable(grouping => grouping.Enabled(true))
    .Footer(true)
    )

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读