5

我有一个简单的页面,里面有 Kendo TabStrip

<div id="main-view" class="k-content">
    @(Html.Kendo().TabStrip()
            .Name("main-view-tabstrip")
            .Items(tabstrip =>
                {
                    tabstrip.Add().Text("My Notices").LoadContentFrom("MyNotices", "Notice").Selected(true);
                }))
</div>

它按需为我加载内容,查询NoticeController. NoticeControllerMyNotices回报我的行动PartialView

public PartialViewResult MyNotices()
{
    // put some values into ViewData

    return PartialView();
}

PartialView 本身看起来像这样:

<div style="margin: 20px; height: 700px;">
    @(Html.Kendo().Grid<NoticeViewModel>(Model)
      .HtmlAttributes(new { @class = "fullScreen" })
      .Name("NoticesList")
      .Columns(columns =>
          {
              columns.Bound(x => x.UniqueId).Title("UniqueId");
              columns.Bound(x => x.FormName).Title("Form");
              columns.Bound(x => x.Revision).Title("Revision");
              columns.Bound(x => x.Language).Title("Language");
              columns.Bound(x => x.Status).Title("Status");
          }
      )
      .Pageable()
      .Scrollable()
      .Sortable()
      .Selectable()
      .ToolBar(
          toolbar => toolbar.Create().Text("New")
      )
        .Editable(
            ed => ed.Mode(GridEditMode.PopUp)
                .TemplateName("NoticeCreate")
                .Window(w => w.Title("Create Notice")
                    .Name("createNoticeWindow1")
                    .HtmlAttributes(new { id = "createNoticeWindow" })
                    .Modal(true)
                    )
                .DisplayDeleteConfirmation(true)
                )
      .Resizable(resize => resize.Columns(true))
      .DataSource(dataSource => dataSource.Ajax()
                                          .PageSize(25)
                                          .ServerOperation(true)
                                          .Read("List", "Notice")
                                          .Create("NoticeCreate", "Notice")
                                          .Events(events => events.Error("errorHandler"))
                                          .Model(model => model.Id(x => x.UniqueId))

      ))
</div>

<script>
    function errorHandler(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>

当我运行代码时,我收到 JS 错误,errorHandler找不到。如您所见,我的PartialView.

<script>
    function errorHandler(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>

所以问题是如何在局部视图中使用 javascript,当你在 TabStrip 中显示它时?

当我.Events(events => events.Error("errorHandler"))从网格中删除时,一切正常。

4

1 回答 1

5

修复了这个问题,我不知道为什么,但是当我把 java 脚本块放在开头时它开始工作。

因此,如果有人遇到此类问题,只需<script/>在声明之前放置块Kendo.Grid()

于 2013-03-21T14:38:17.373 回答