Kendo TabStrip with KendoGrid internally using JavaScript to handle events

I have a simple page with Kendo TabStrip inside

<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>

He downloads content for me on request, requesting NoticeController. NoticeControllerhas a MyNoticesreturn action me PartialView.

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

    return PartialView();
}

The PartialView element is as follows:

<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>

When I run the code, I get a JS error that errorHandlercannot be found. As you can see, I have it inside 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>

So the question is, how to use javascript inside a partial view when you show it inside a TabStrip?

When I remove .Events(events => events.Error("errorHandler"))from the grid, everything works fine.

+5
source share
1 answer

​​, , java script , .

, - ​​, <script/> Kendo.Grid().

+5

All Articles