MVC kendo窗口-从javascript函数获取数据 [英] MVC kendo window - Get Data from javascript function
问题描述
我的应用程序中有这个剑道窗口
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"))
而且我正在尝试将数据传递给javascript函数返回的LoadContentFrom()中的acrion,但我不知道该怎么做.我可以这样传递数据:
And I am trying to pass data to the acrion in the LoadContentFrom() wich 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" })
但这不是我想要的.
JS功能:
function getInfo() {
return { type: "INPUT" };
};
我的控制器:
public ActionResult CopyStructure(string type)
{
return PartialView();
}
推荐答案
如果您确实需要通过JavaScript getInfo()
函数访问数据,那么执行此操作的方法是在执行操作时定义Window,但不要在打开窗口之前,请先设置内容.打开窗口时,使用jQuery.ajax()
调用CopyResult
,将getInfo()
的结果传递到data参数中.
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.
在剃刀中,取出LoadContentFrom
为Open
事件添加事件处理程序:
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"))
)
然后在JavaScript的处理程序中,调用$.ajax
并在success
回调中,对Window对象调用content
方法,并将返回的data
作为参数传递给该对象:
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);
}
});
}
请注意,仅发送窗口内容所需的内容,而不发送整页内容(DOCTYPE,html,标题,正文)-请参阅Telerik的以下文档:
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 kendo窗口-从javascript函数获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!