2

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();
    }
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Yatiac
  • 1,820
  • 3
  • 15
  • 25
  • What happens when you replace `"NewXmlLayout"` with `getInfo()`? What do you mean by "not what I'm looking for"? – DanM7 Jun 18 '14 at 21:24
  • `"NewXmlLayout"` is my controller and `CopyStructure` is my Action. – Yatiac Jun 19 '14 at 12:34

1 Answers1

9

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

Andrew Trevers
  • 1,246
  • 8
  • 10
  • thank you, i was pulling my hair off with loadcontentfrom with mvc partial view while i forgot to set layout to null – uowzd01 Apr 27 '15 at 07:47