Reputation:
I am stuck at what appears to be a very simple scenario:
Loading a Kendo window with a partial view bound to a model, with a dynamic parameter modelId
that will be provided by client side js.
I found out about the refresh()
method, but this implies that there is already a kendo window intialized. That's the first problem. I need the the modelId
to display content.
So I worked around this issue and simply returned a new model intially which than should be replaced/refreshed by the refresh()
method + a valid parameter modelId
and finally be displayed.
Problem: The view won't be updated.
The refresh()
method actually works, though.
The controller receives the parameter modelId
, fetches the corresponding model and returns the view. But the Kendo window still holds the empty viewmodel instead.
I tryed really hard to get this to work but without success..
@(Html.Kendo().Window()
.Name("window")
.Title("")
//loads an empty viewmodel intially as there is no possibility to pass parameter
.LoadContentFrom("Actionname", "Controller")
.Actions(actions => actions.Close())
.Modal(true).Visible(false)
.HtmlAttributes(new {style = "margin: 10px"})
)
Javascript snippet:
$("#window").data("kendoWindow").refresh({
url: '/controller/actionname/',
data: { parameterlabel: parameter}
});
$("#window").data("kendoWindow").open().center(true);
Upvotes: 3
Views: 8223
Reputation: 601
First time I saw this issue with:
wnd.refresh({
url: msg.Url,
type: "POST",
contentType: "application/json",
dataType: "json",
data: msg.Data
});
and the Kendo Window was empty. The request in Fiddler (some headers and data removed):
POST http://localhost/My/PtsSchedule/Pts_AddBooking HTTP/1.1
Accept: application/json, text/javascript, */*; q=0.01
Content-Type: application/json
The problem was apparently in:
Accept: application/json, text/javascript, /; q=0.01
and removing dataType: solved the issue for me. Here the new refresh:
wnd.refresh({
url: msg.Url,
type: "POST",
contentType: "application/json",
data: msg.Data
});
and in Fiddler:
POST http://localhost/My/PtsSchedule/Pts_AddBooking HTTP/1.1
Accept: text/html, */*; q=0.01
Content-Type: application/json
and the content was displayed within the Kendo Window. Hope this is from help.
Upvotes: 1
Reputation:
..could it be that I got it wrong and the refresh() method acutally doesn't need a fully loaded kendo window with content in the first place? I found this on teleriks page: " If you want to load content in the window dynamically (through AJAX), you can do so by:
//set up kendo window
$(document).ready(function () {
var window = $("#window").kendoWindow({
height: "200px",
modal: true,
title: "Centered Window",
visible: false,
width: "200px"
}).data("kendoWindow");
});
//using the refresh method after the window has been intialized:
var dialog = $("#window").data("kendoWindow");
dialog.refresh({
url: "/search",
data: { query: "foobar" }
}); "
.. not excaclty what I'd expect of a refresh but okay.. So maybe I should just remove the load content in the created kendo window:
@(Html.Kendo().Window()
.Name("window")
.Title("")
//.LoadContentFrom("Actionname", "Controller", new { modelID = modelId })
.Actions(actions => actions.Close())
.Modal(true).Visible(false)
.HtmlAttributes(new {style = "margin: 10px"})
)
Upvotes: 3
Reputation: 12875
Not sure if this solves your main issue, but you should be able to do this:
@(Html.Kendo().Window()
.Name("window")
.Title("")
.LoadContentFrom("Actionname", "Controller", new { modelID = modelId })
.Actions(actions => actions.Close())
.Modal(true).Visible(false)
.HtmlAttributes(new {style = "margin: 10px"})
)
Then you won't need to load the empty model and refresh it with the correct parameter.
Upvotes: 1