This is a migrated thread and some comments may be shown as answers.

Passing data to a window

3 Answers 1367 Views
Window
This is a migrated thread and some comments may be shown as answers.
Ricky
Top achievements
Rank 1
Ricky asked on 10 Jul 2018, 11:45 AM

Hi I'm enumerating though a model and want to pass the current data n to a Window when edit is clicked.

@foreach (var n in Model) {
    <tr>
        <td class="grb-fa-center">
            <i class="far fa-edit fa-lg" title="Edit" onclick='$("#window").data("kendoWindow").open();'></i
        </td>
    </tr>
 <div id="example">
    @(Html.Kendo().Window()
        .Name("window")
        .Title("My Editor")
        .Content(@<text>@Html.Partial("MyEditor\\Index", n)</text>)
.Visible(false)                                                                                                                             .Width(400)
    )
</div>

How can I pass n to my window?

 

Thanks,

Ricky

3 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Tsvetanov
Telerik team
answered on 13 Jul 2018, 07:41 AM
Hello Ricky,

In order to pass data and load the Window content from a partial view, I would recommend you to use the widget LoadContentFrom("[action]", "[controller]") configuration option. In such case the Window HTML helper will have the following definition:
@(Html.Kendo().Window()
    .Name("window")
    .Title("My Editor")
    .LoadContentFrom("MyEditor", "Home")
    .Visible(false)
    .Width(400)
)

To pass the data to the partial, the refresh() method of the widget should be used:
<i class="far fa-edit fa-lg" title="Edit" onclick='$("#window").data("kendoWindow").refresh({ data: { id: "@n" } }).open();'>Edit @n</i>

Where the MyEditor action will return the partial:
public IActionResult MyEditor(string id)
{
    return PartialView("MyEditor", id);
}

And the partial will render the data passed:
@model string
 
<h2>MyEditor</h2>
 
ID is: @Model

Attached you will find a small sample implementing the above.

Regards,
Veselin Tsvetanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Ricky
Top achievements
Rank 1
answered on 17 Jul 2018, 10:37 AM

I can't get your example app to run, it seems to be badly broken and complains it can't find namespace 'System'. All the NuGet dependencies and the SDK seem to be missing and have yellow warning triangles.

However I was able to follow what you've provided and got that to work on my system using a standard string instead of @n.

As soon as I try to pass @n nothing gets passed but a null. I've also tried to use @n.id to pass an int as a string, but this doesn't work either.

Can you please help.

 

Thanks,

Ricky

1
Ricky
Top achievements
Rank 1
answered on 17 Jul 2018, 01:59 PM

OK. I got it to work by passing the id as a string and loading the full model in my controller to pass to the partial view.

 

Thanks,

Ricky

Tags
Window
Asked by
Ricky
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Ricky
Top achievements
Rank 1
Share this question
or