我有一个剑道菜单,我希望每个菜单都可以打开一个新窗口。我该如何实现?
这是我当前的代码_layout
:
<div class="k-rtl">
@(Html.Kendo().Menu()
.Name("menu")
.Items(items =>
{
items.Add().Text("Menu 1").Items(child =>
{
child.Add().Text("1").LinkHtmlAttributes(new { onClick = "menu('1');" });
child.Add().Text("2");
});
})
)
</div>
<script>
function menu(text) {
var window = $("#win1").data("kendoWindow");
switch (text) {
case "1":
window.refresh({ url: "@Url.Action("Index", "1")" }).title("1");
break;
case "2":
window.refresh({ url: "@Url.Action("Index", "2")" }).title("2");
break;
}
window.open();
}
</script>
然后在索引中创建此默认窗口:
@(Html.Kendo().Window()
.Name("win1")
.Title("default")
.LoadContentFrom("Index", "default")
.Draggable()
.Resizable()
.Actions(actions => actions.Close().Minimize().Refresh())
.Position(p => p.Top(100))
)
这段代码有两个问题:
要拥有多个窗口,您可以创建一个局部视图,然后将其注入HTML代码(@Html.Partial("MyGenericWindow")
),以确保每次都生成一个新的窗口ID(名称)。
像这样:
@{
var windowId = Guid.NewGuid().ToString();
}
@(Html.Kendo().Window()
.Name(windowId )
.Draggable()
.Resizable()
.Actions(actions => actions.Close().Minimize().Refresh())
.Position(p => p.Top(100))
)
要解决刷新问题,请尝试以下操作:
function menu(text) {
var window = $("#@windowId").data("kendoWindow");
window.title(text);
window.refresh({
url: '@Url.Action("Index")',
data: { myParam: text }
});
window.bind("refresh", function () {
window.center();
window.open();
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句