MVC 剑道窗口 - 从 JavaScript 函数中获取数据 [英] MVC kendo window - Get Data from JavaScript function

查看:15
本文介绍了MVC 剑道窗口 - 从 JavaScript 函数中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有这个剑道窗口

Html.Kendo().Window().Name(复制结构").Title(复制结构").Content("加载中...").LoadContentFrom("CopyStructure", "NewXmlLayout")//<-- 这里*.可拖动(假).可见(假).模态(真).Actions(s => s.Custom("")).Events(e => e.Open(openWindow").Close(closeWindow"))

我正在尝试将数据传递给 JavaScript 函数返回的 LoadContentFrom() 中的操作,但我不知道该怎么做.我可以这样传递数据:

.LoadContentFrom("CopyStructure", "NewXmlLayout", new { type= "INPUT" })

但这不是我要找的.

JS 函数:

function getInfo() {返回 { 类型:输入";};};

我的控制器:

 public ActionResult CopyStructure(string type){返回 PartialView();}

解决方案

如果你真的需要通过 JavaScript getInfo() 函数访问你的数据,那么这样做的方法是定义按您正在执行的操作打开窗口,但在打开窗口之前不要设置内容.打开Window时,使用jQuery.ajax()调用CopyResult,将getInfo()的结果传入data参数.

在你的 Razor 中,取出 LoadContentFromOpen 事件添加一个事件处理程序:

@(Html.Kendo().Window().Name("复制结构")//为简洁起见省略....Events(e => e.Open("copyStructure_Open")))

在你的 JavaScript 处理程序中,调用 $.ajax 并在 success 回调中,调用传递 Window 对象的 content 方法返回的data作为参数:

function copyStructure_Open(e) {$.ajax({url: '@Url.Action("CopyStructure", "NewXmlLayout")',类型:'POST',数据:getInfo(),成功:功能(数据){e.sender.content(data);}});}

请注意仅发送窗口内容所需的内容,而不是完整页面(DOCTYPE、html、head、body) - 请参阅 Telerik 的此文档:http://docs.telerik.com/kendo-ui/getting-started/web/window/overview#loading-window-content-via-ajax

I have this kendo window in my app

Html.Kendo().Window()
    .Name("copyStructure")
    .Title("Copy Structure")
    .Content("Loading...")
    .LoadContentFrom("CopyStructure", "NewXmlLayout") // <-- here*
    .Draggable(false)
    .Visible(false)
    .Modal(true)
    .Actions(s => s.Custom(""))
    .Events(e => e.Open("openWindow").Close("closeWindow"))

And I am trying to pass data to the action in the LoadContentFrom() which is returned by a JavaScript function, but I don't know how to do it. I can pass data like this:

.LoadContentFrom("CopyStructure", "NewXmlLayout", new { type= "INPUT" })

But is not what I'm looking for.

The JS function:

function getInfo() {
        return { type: "INPUT" };
    };

My controller:

 public ActionResult CopyStructure(string type)
    {
        return PartialView();
    }

解决方案

If you really need to access your data via the JavaScript getInfo() function, then the way to do this is to define the Window as you are doing but don't set the content until you open the window. When opening the Window, use jQuery.ajax() to call CopyResult, passing the results of getInfo() into the data parameter.

In your Razor, take out LoadContentFrom add an event handler for the Open event:

@(Html.Kendo().Window()
    .Name("copyStructure")
    // Omitted for brevity
    ...
    .Events(e => e.Open("copyStructure_Open"))
)

And in your handler in JavaScript, call $.ajax and in the success callback, call the content method on the Window object passing the returned data as the parameter:

function copyStructure_Open(e) {
    $.ajax({
        url: '@Url.Action("CopyStructure", "NewXmlLayout")',
        type: 'POST',
        data: getInfo(),
        success: function(data) {
            e.sender.content(data);
        }
    });
}

Beware to only send what's required for the window content, and not a full page (DOCTYPE, html, head, body) - see this documentation from Telerik: http://docs.telerik.com/kendo-ui/getting-started/web/window/overview#loading-window-content-via-ajax

这篇关于MVC 剑道窗口 - 从 JavaScript 函数中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆