javascript 如何在按钮单击事件上将视图加载为剑道窗口弹出窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22795673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to load a View as Kendo Window popup on Button Click Event
提问by user3470946
I am trying to load a view in a kendo window onlyon click button's event. Actually, the popup is displayed each time on the load of the base page. I want that that popup loads only on the click event of the button.
我试图仅在单击按钮事件时在剑道窗口中加载视图。实际上,每次加载基本页面时都会显示弹出窗口。我希望该弹出窗口仅在按钮的单击事件上加载。
Am I missing something? I've also added onclick event in the html button and called openWindow() javascript method. But it didn't work either, apparently something is wrong.
我错过了什么吗?我还在 html 按钮中添加了 onclick 事件并调用了 openWindow() javascript 方法。但它也没有奏效,显然有什么地方不对劲。
Is it possible to put the server code of kendo Window below in a jquery function? If yes, how?
是否可以将kendo Window的服务器代码放在jquery函数中?如果是,如何?
<% Html.Kendo().Window()
.Name("partListGridWindow")
.Width(800)
.......
%>
Here is my code JQuery:
这是我的代码 JQuery:
$(document).ready(function () {
$("#partListLink")
.bind("click", function () {
$("#partListGridWindow").data("kendoWindow").open().center();
});
});
The kendo Window: In the LoadContentFrom I call PartList which is the Action Name that return my View, from Claim Controller.
剑道窗口:在 LoadContentFrom 中,我调用 PartList,它是从 Claim Controller 返回我的视图的操作名称。
<% Html.Kendo().Window()
.Name("partListGridWindow")
.Width(800)
.Modal(true)
.Title("Part List Info")
.Content("Loading Part List Info...")
.LoadContentFrom("PartList", "Claim", Model)
//.Visible(false)
.Draggable()
.Resizable()
.Render();
%>
Here is the html button:
这是 html 按钮:
<a id="partListLink" class="k-button" onclick=openWindow()></a>
By the way, I saw on the Telerik forum they recommend this formula to hide the window with Visible = falsebut it should be a way to bypass the load of those windows at the beginning of the base page load.
顺便说一句,我在 Telerik 论坛上看到他们推荐这个公式来隐藏Visible = false的窗口,但它应该是一种在基本页面加载开始时绕过这些窗口加载的方法。
What to do in the case there are tens or more of popup windows to load?
如果要加载数十个或更多弹出窗口,该怎么办?
Any help is greatly appreciated! Thank you so much for ur help!
任何帮助是极大的赞赏!非常感谢您的帮助!
回答by CSharper
If your Kendo Window is populating when the base page Loads you have to set
.Visible(false)
. This is how we've done it in our previous project.
如果您的 Kendo 窗口在基本页面加载时填充,您必须设置
.Visible(false)
. 这就是我们在之前的项目中所做的。
This is the click event
这是点击事件
function clientLaunchWindow() {
var window = $("#Window").data("kendoWindow");
window.refresh({
url: "/Order/LaunchWindow"
});
window.center();
window.open();
Your Controller will just return the partial view
您的控制器只会返回部分视图
public ActionResult LaunchWindow()
{
return PartialView("_PartialView");
}
回答by Sameel
Hello Mate I understand your issue really well. it seems kendo's default feature that it loads content with it's base page load. You should add content instead of LoadcontentFrom chain. and define a div and set a id for that. The in the button click function you should do a ajax call and get the content and load into id that you set for the div.
你好,伙计,我非常理解你的问题。似乎 kendo 的默认功能是通过它的基本页面加载来加载内容。您应该添加内容而不是 LoadcontentFrom 链。并定义一个 div 并为此设置一个 id。在按钮单击功能中,您应该执行 ajax 调用并获取内容并加载到您为 div 设置的 id 中。
<% Html.Kendo().Window()
.Name("partListGridWindow")
.Width(800)
.Modal(true)
.Title("Part List Info")
.Content(@<text>
<div id="WindowContent"> </div> </text>)
.Visible(false)
.Draggable()
.Resizable()
.Render();
%>
Your button is:
你的按钮是:
function openWindow(e) {
var GridWindow = $("#partListGridWindow");
GridWindow.data("kendoWindow").open().center();
$.ajax({
type: "GET",
url: '@Url.Action("LaunchWindow", "Controller")',
cache: false,
data: { "x": 1 },
success: function (result) {
if (result) {
$("#WindowContent").html(result);
}
else {
$("#WindowContent").html(<h2>No Content found</h3>)
}
}
});
}