网格中的Telerik ASP.NET Core自定义字段编辑器未显示数据

时间:2019-06-05 13:53:50

标签: asp.net-core razor telerik

我正在使用Telerik ASP.NET Core Grid,它工作正常。 但是,当我尝试使用“编辑器”组件编辑文本字段时,它最初不显示 Document1 文本,我想这是一个绑定问题。

具有UIHint的我的模型:

namespace XYZ_Website.Models
{
    public partial class Contracts
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Details { get; set; }
        [UIHint("RichEdit_Contracts")]
        public string Document1 { get; set; }
        public DateTime? Date { get; set; }
    }
}

网格剃刀为:

@model IEnumerable<Contracts>
@using Kendo.Mvc.UI

@{
    Layout = "_LayoutAdmin";
    ViewData["Title"] = "Contracts Admin";
}

<h1>Contracts Management</h1>

<style>
    .k-edit-form-container {
        width:100% !important;
        height: 90% !important;
        left:0 !important;
    }

    .k-edit-form-container .editor-field {
        width: 80% !important;
    }

    .k-edit-form-container .editor-label, .k-edit-label {
        width: 10% !important;
    }

    .k-window {
    left:0px !important;
    }
</style>

@(Html.Kendo().Grid<Contracts>()
      .Name("Contracts")
      .Columns(columns =>
      {
          columns.Bound(p => p.Date).Title("date").Width(130);
          columns.Bound(p => p.Title).Title("title").Width(170);
          columns.Bound(p => p.Details).Title("details").Width(130);
//          columns.Bound(p => p.Document1).Title("Document1").Width(130);
          columns.Bound(p => p.Document1).ClientTemplate("<a href='"+Url.Content("PreviewContract?contract=")+"#: Id#'><span class='k-icon k-i-attachment-45' style='color:red;opacity:1'></span> <span style='background-color:red;color:yellow;border-radius:4px;padding:4px'>Contracts Content</span></a>");
//          columns.Template("<a onclick='return confirm(\"It will deduct 3 credits from your account, continue?\");' href='"+Url.Content("/Contracts/PreviewPDF?pdf=")+"#: Document1#'><span class='k-icon k-i-attachment-45' style='color:green;opacity:1'></span></a>").Width(100).Title("Preview & Download");
          columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160);
      })
      .ToolBar(toolbar =>
      {
          toolbar.Create();
          toolbar.Save();
      })
      .Editable(editable => editable.Mode(GridEditMode.PopUp))
      .Pageable()
      .Sortable()
      .Scrollable(scr => scr.Height(430))
      .Filterable()
      .DataSource(dataSource => dataSource
          .Ajax()
          .ServerOperation(false)
          .PageSize(20)
//          .ServerOperation(false)
          .Events(events => events.Error("error_handler"))
          .Model(model =>
          {
              model.Id(p => p.Id);
          })
          .Create(update => update.Action("Contracts_Create", "Admin"))
          .Read(read => read.Action("Contracts_Read", "Admin"))
          .Update(update => update.Action("Contracts_Update", "Admin"))
          .Destroy(update => update.Action("Contracts_Destroy", "Admin"))
      )
      )
<script type="text/javascript">
    function error_handler(e) {
        if (e.errors) {
            var message = "Errors:\n";
            $.each(e.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += this + "\n";
                    });
                }
            });
            alert(message);
        }
    }
</script>

最后是客户编辑器RichEdit_Contracts是:

@model string

@Html.HiddenFor(m => m)
@Html.ValidationMessageFor(m => m)

<script>
    function onChange(e) {
        var contents = e.sender.body.innerHTML;
        $("#Document1").val(contents).trigger("change");
    }
</script>


<div >

    <div class="demo-section k-content">
        @(Html.Kendo().Editor()
              .Name("editor")
              .HtmlAttributes(new { style = "height:440px", aria_label = "editor" })
              .Resizable(resizable => resizable.Content(true).Toolbar(true))
              .Events(events => events
                  .Change("onChange")
              )

              )
    </div>
</div>

0 个答案:

没有答案