内部に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
. return me のアクションがありNoticeController
ます。MyNotices
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>
コードを実行すると、errorHandler
見つからない JS エラーが表示されます。あなたが見ることができるように、私はそれを私の中に持っています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>
問題は、TabStrip 内で表示するときに、部分ビュー内で JavaScript を使用する方法です。
.Events(events => events.Error("errorHandler"))
グリッドから削除すると、すべて正常に動作します。