【问题标题】:How to load a View as Kendo Window popup on Button Click Event如何在按钮单击事件上加载视图作为剑道窗口弹出窗口
【发布时间】:2014-04-01 19:56:37
【问题描述】:

我正在尝试在单击按钮事件时在剑道窗口中加载视图。 实际上,每次加载基本页面时都会显示弹出窗口。我希望该弹出窗口仅在按钮的单击事件上加载。

我错过了什么吗?我还在 html 按钮中添加了 onclick 事件并调用了 openWindow() javascript 方法。但它也没有工作,显然有问题。

是否可以将kendo Window的服务器代码放在jquery函数中?如果是,如何?

<% Html.Kendo().Window()
      .Name("partListGridWindow")
      .Width(800)
.......
%>

这是我的代码 JQuery:

$(document).ready(function () {
   $("#partListLink")
        .bind("click", function () {
            $("#partListGridWindow").data("kendoWindow").open().center();
        });
});

剑道窗口: 在 LoadContentFrom 中,我从 Claim Controller 调用 PartList,它是返回我的视图的操作名称。

<% 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();
%>

这里是html按钮:

<a id="partListLink" class="k-button" onclick=openWindow()></a>

顺便说一句,我在 Telerik 论坛上看到他们推荐这个公式来隐藏带有 Visible = false 的窗口,但这应该是一种绕过负载的方法那些在基础页面开始加载的窗口。

如果要加载几十个或更多的弹出窗口怎么办?

非常感谢任何帮助! 非常感谢您的帮助!

【问题讨论】:

    标签: javascript jquery asp.net-mvc modalpopupextender onclientclick


    【解决方案1】:

    如果您的 Kendo 窗口在基本页面加载时填充,您必须设置 .Visible(false)。这就是我们在之前的项目中所做的。

    这是点击事件

    function clientLaunchWindow() {
    
         var window = $("#Window").data("kendoWindow");
    
         window.refresh({
                 url: "/Order/LaunchWindow"        
         });      
         window.center();
         window.open();
    

    你的控制器只会返回部分视图

    public ActionResult LaunchWindow()
        {
           return PartialView("_PartialView");
        }
    

    【讨论】:

    • 感谢您的回复。是的,当基本页面加载时,我的 Kendo Windo 正在填充,这是我试图避免的,因为我的基本页面中有很多窗口弹出窗口,我相信这应该是一个更好的方法,当我从单击按钮调用每个窗口时需要加载它。 Visible = false 意味着我的 Window 只是被隐藏了,但它存在并且比它加载的更多。那么我在action方法中传递给Controller的参数呢,如何传递呢?再次感谢您的帮助!
    • 好的,我明白你的意思了,所以你担心性能,因为不管它是否显示,窗口都会被加载。如果可能的话,我不确定如何处理这个问题。通过查询字符串传递参数。你的网址变成url: "/Order/LaunchWindow/?YourParamName=Value" 那语法应该是正确的,你甚至可以只做url: "/Order/LaunchWindow/Value"
    • 你可以在这里看到他是如何通过查询字符串传递参数的。 asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/…
    • 这个例子帮助我将参数传递给我的控制器,thanx @CSharper :)
    • 我们可以在剑道窗口中加载整个视图而不是部分视图吗?
    【解决方案2】:

    你好,伙计,我非常了解你的问题。剑道的默认功能似乎是通过其基本页面加载来加载内容。 您应该添加内容而不是 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();
    %>
    

    您的按钮是:

    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>)
                        }
                    }
                });
    }
    

    【讨论】:

    • 你的按钮是:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多