c# - Kendo TabStrip with KendoGrid inside using JavaScript for Events handling - Stack Overflow

I have simple page with Kendo TabStrip inside<div id="main-view" class="k-content&quo

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

It loads content for me on demand, querying the NoticeController. NoticeController has MyNotices action with return me PartialView.

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

    return PartialView();
}

The PartialView itseld looks like this:

<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 receive JS error, that errorHandler cannot be found. As you can see I have it inside my 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 partial view, when you show it inside TabStrip?

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

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

It loads content for me on demand, querying the NoticeController. NoticeController has MyNotices action with return me PartialView.

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

    return PartialView();
}

The PartialView itseld looks like this:

<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 receive JS error, that errorHandler cannot be found. As you can see I have it inside my 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 partial view, when you show it inside TabStrip?

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

Share Improve this question edited Mar 21, 2013 at 11:22 Jevgenij Nekrasov asked Mar 21, 2013 at 11:15 Jevgenij NekrasovJevgenij Nekrasov 2,7703 gold badges32 silver badges52 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Fixed the issue, I do not why, but when I put java script block at the beginning it starts to work.

So if someone meet such issue just put <script/> block before declaring Kendo.Grid().

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744839029a4596442.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信