Passing Action Data to a Window

4 posts, 0 answers
  1. Rich Lasker
    Rich Lasker avatar
    11 posts
    Member since:
    May 2008

    Posted 05 Apr 2013 Link to this post

    I'm following the basic model of displaying a window from an action in a Kendo Grid. The content of the window needs to be loaded via a Partial View from an Action but I cannot figure out how to pass data to the Window so that when it loads the View it can pass that data along. I need to accomplish something akin to the code below.

    @(Html.Kendo().Grid<ActivationModel>()
       .Name("activationGrid")
            .Columns(columns =>
       {
                columns.Bound(p => p.RawMessageId).Hidden();
                columns.Command(command => command.Custom("SendActivation").Text("Re-send Activation Email").Click("sendActivation"));
            })
    .DataSource(dataSource => dataSource
                .Ajax()
                .ServerOperation(false)
                .PageSize(20)
                .Read(read => read.Action("Activations", "Activation"))
                .Model(model => model.Id(k => k.RawMessageId))
            )
    )
        @(Html.Kendo().Window().Name("ActivationWindow")
        .Title("Customer Details")
        .Visible(false)
        .Modal(true)
        .Draggable(true)
        .Width(300)
        .LoadContentFrom("Activation", "ResendActivation", new { rawId = [NEED TO INSERT DATA HERE] })
    )

    <script type="text/javascript">
        function sendActivation(e) {
            e.preventDefault();
            var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
            var wnd = $("#ActivationWindow").data("kendoWindow");
            wnd.center().open();
        }
    </script>
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 09 Apr 2013 Link to this post

    Hello Rich,

    I am not sure that I understand the exact question. Basically when using the LoadContentFrom - you should pass your data just as you showed (after all that LoadContentFrom option generates a URL which is used by the $.ajax call on the client / or the iFrame if iFrame is set to true):
    e.g.

    //view
    @(Html.Kendo().Window().Name("name").LoadContentFrom("About", "Home", new { test = "foo"})))
     
    //action
            public ActionResult About(string test)
            {
                ViewBag.Message = "Your quintessential app description page.";
     
                return View();
            }

    If you are trying to pass additional data when you load the window dynamically on the client side then you need to use the refresh method like explained in the documentation.

    http://docs.kendoui.com/api/web/window#methods-refresh


    Kind Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Rich Lasker
    Rich Lasker avatar
    11 posts
    Member since:
    May 2008

    Posted 09 Apr 2013 Link to this post

    I'm trying to pass information that is contained in the Grid so in your example:

    @(Html.Kendo().Window().Name("name").LoadContentFrom("About",
    "Home", new { test = "foo"})))

    "foo" would be a value in a cell that would need to be dynamically passed to the LoadContentFrom method.

    Essentially you could take the example here:

    http://demos.kendoui.com/web/grid/custom-command.html

    With the difference being that I want to Load the content from an action instead of a template. I found a solution but it is by using an iframe in the template and constructing the url manually:

    <script type="text/x-kendo-template" id="template">
        <div id="activation-container">
            <iframe style="width:380px; height:280px; border-width: 0px;" src="/Activation/ResendActivation?rawId=#= RawMessageId #&amp;userName=#= UserName #" />
        </div>
    </script>
  5. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 11 Apr 2013 Link to this post

    Hello Rich,

    Thank you for pointing an example. Basically you will need to use the refresh method as I mentioned in my previous post. The difference would be that in the showDetails function you will need to make a similar call to the one:

    function showDetails(e) {
                       e.preventDefault();
     
                       var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
                       wnd.refresh({
                                           url: "/yourUrl",
                                         data: { FirstName: dataItem.FirstName}
                       });
                       wnd.center().open();
                   }


    Kind Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready