【问题标题】:Lazy loading Telerik window content延迟加载 Telerik 窗口内容
【发布时间】:2012-11-29 04:17:16
【问题描述】:

我正在使用 ASP.NET MVC 3 并使用 Telerik。我有一个空的 Telerik 窗口。我的目标是仅在用户单击按钮时向服务器询问内容,但是我不知道如何做到这一点。我想要做到这一点,我需要存储对相关 Telerik 窗口的引用。但是我该怎么做呢?请帮忙。这是我已经走了多远:

@{
   Html.Telerik().Window()
   .Name("ImportDialog")
   .ClientEvents(events => events.OnOpen("DialogOpen"))
   .Visible(false)
   .Title("Import users")
   .Draggable(false)
   .Resizable(resizing => resizing.Enabled(false))
   .Modal(true)
   .Width(400)
   .Height(400)
   .Render();
}

我确实想在 DialogOpen 函数中做点什么,或者用服务器端函数替换客户端函数....

【问题讨论】:

    标签: c# asp.net-mvc-3 telerik telerik-mvc


    【解决方案1】:

    我找到了一种答案,但我不确定它是否是最好的。

    在javascript函数DialogOpen中,我发送一个ajax请求到一个url(在MVC中也称为Controller的一个Action),我把结果放在对话框窗口的内容中,如下所示:

    function DialogOpen () 
    {
     $.ajax({
        type: "POST",
        url: "Controller/Action",
        data: "name=John&location=Boston",
        success: function (htmlContent) 
        {
            $('#ImportDialogContent').html(htmlContent);
        },
        error: function () 
        {
            $('#ImportDialogContent').html("<p>Could not import user data at this time</p>");
        }
     });
    }
    

    P.S.:我给 Telerik Window(ImportDialogContent) 的内容区域提供了一个 ID!

    【讨论】:

      【解决方案2】:

      您应该使用 Telerik Window 的客户端 API,更具体地说是 ajaxRequest 方法。

      因此,例如,当单击按钮时,您应该获取客户端对象并调用 ajaxRequest 方法,这将使 Window 从该 MVC 操作方法中检索其内容。 例如

      function DialogOpen(){
          var myWin= $('#ImportDialog').data('tWindow');
          myWin.ajaxRequest("Controller/Action", { name: "John",location:"Boston"});
      }
      

      【讨论】:

        猜你喜欢
        • 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
        相关资源
        最近更新 更多