5
的JavaScript我有简单的页面与剑道TabStrip控件内剑道TabStrip控件与KendoGrid内使用事件处理
<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
。 NoticeController
已将MyNotices
动作返还给我PartialView
。
public PartialViewResult MyNotices()
{
// put some values into ViewData
return PartialView();
}
的PartialView itseld看起来是这样的:
<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"))
时,一切工作正常。
我已经看到这个行为以及与Kendo和mvc服务器包装,重新:JS服务器端包装器中声明的事件需要写在包装上。 – 2013-03-21 16:08:38
如果您在页面加载期间打开控制台,您可能会看到类似“errorHandler未声明”的错误。 这是因为在页面被加载时,Kendo小部件会查找该函数,如果它在下面声明,则意味着该网格将无法找到它,因为它仍然需要被解析。 – Pizzaboy 2015-06-30 08:10:39