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

[Solved] LoadContentFrom, window.AjaxRequest not working... a little hopeless but still trying...

4 Answers 289 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Max
Top achievements
Rank 1
Max asked on 25 Nov 2011, 06:52 PM

Hi all

Another user here trying to achieve a simple task. I have read all the posts here and even though I know I am missing something simple,
I cannot find an answer to this issue. I get a little hopeless when I see so many answered questions here...anyways..

The goal is to display a Chart in a popup window. The Chart IS displayed but ONLY once.
The partial View is NOT being called so the NEW data with the NEW parameters is NOT being fetched.
Here is my code:

    public class NormalModeController : Controller
    {
        ... some code here

        public PartialViewResult _ChartBottom(string upgradeDate, string name)
        {
            return PartialView("_ChartBottomData", GetUpdatedData(upgradeDate, name));
        }


VIEW: (this will load only ONCE)

<div id="linkBottomGraph-region">
@{ Html.Telerik().Window()
        .Name("WindowBottomGraph")
        .Visible(false)
        .Scrollable(true)
        ... ommited some code here blah blah blha
        .Buttons(b => b.Refresh().Maximize().Close())
        //.LoadContentFrom("_ChartBottom", "NormalMode", new { upgradeDate = ViewData["UpgradeDate"], name = ViewData["name"] })
        .LoadContentFrom(Url.Action("_ChartBottom", "NormalMode", new { upgradeDate = ViewData["UpgradeDate"], name = ViewData["name"] }))
        .Render();
}
</div>

<script type="text/javascript">

    function openBottomWindow() {
        var window = $("#WindowBottomGraph").data("tWindow");

        window.ajaxRequest("#linkBottomGraph-region", "NormalMode/_ChartBottom/"); //this calls the whole page, not the partial HTML...weird
        window.open();
    }
</script>

PARTIAL VIEW:

@model IEnumerable<ViewModels.NormalMode.MyModelTest>

    @(Html.Telerik().Chart(Model)
    .Name("Grid1")
    ... omitted some code here blah blah
    //.DataBinding(dataBinding => dataBinding.Ajax().Select("_ChartBottomData", "NormalMode")
    //)
    .HtmlAttributes(new { style = "width: 1000px; height: 300px;" })
)

Any ideas?

Thank you

4 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 28 Nov 2011, 08:46 AM
Hi Max,

The signature of the ajaxRequest method is ajaxRequest(url, data). You may call it like this: window.ajaxRequest("NormalMode/_ChartBottom/") to completely refresh the window contents. If you want to refresh only the element with the id linkBottomGraph-region, you need to make the AJAX request by yourself.

All the best,
Alex Gyoshev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Max
Top achievements
Rank 1
answered on 28 Nov 2011, 04:40 PM
Hey Alex,

I was trying to use the ClientSideApi sample: http://demos.telerik.com/aspnet-mvc/razor/window/clientsideapi?theme=vista
In that sample, when you click REFRESH, the partial view is called with the new data. Not sure why in my scenario that is not
working though.

From my understanding "LoadContentFrom" loads only once but apparently the window.Refresh() method is able to call it again.
I don't want to replace the DIV but want to replace the contents inside the Telerik window. I followed your advice by correcting the URL and I see that the partial method is being called now BUT the parameters are not being passed.

From your help file: "The ajaxRequest method reloads the Window content with the data returned from the supplied url. If the url parameter is omitted, the current LoadContentFrom url is used."

Well, my LoadContent is:
.LoadContentFrom(Url.Action("_ChartBottom", "NormalMode", new { upgradeDate = ViewData["UpgradeDate"], vhoName = ViewData["VhoName"] }))

window.ajaxRequest(); //parameters are passed but content window is blank

and when I try to explicitly pass the parameters I get an error: ViewData is  undefined in one of the lines below:

window.ajaxRequest("NormalMode/_ChartBottom/", { upgradeDate: ViewData["UpgradeDate"] });
or
window.ajaxRequest("NormalMode/_ChartBottom/", { upgradeDate: ViewData["UpgradeDate"], vhoName : ViewData["VhoName"] });

 So I am stuck :(
Thanks


0
Accepted
Alex Gyoshev
Telerik team
answered on 30 Nov 2011, 01:30 PM
Hi Max,

Indeed, ViewData is undefined in JavaScript, as it is part of the view engine. You need to output it in the generated JavaScript, like @ViewData["UpgradeDate"]. Furthermore, because this will output the date as JavaScript code, you need to place it in quotes, so that it outputs it as a string. Thus, the correct code should be:

window.ajaxRequest("NormalMode/_ChartBottom/", { upgradeDate: '@ViewData["UpgradeDate"]', vhoName : '@ViewData["VhoName"]' });

Greetings,
Alex Gyoshev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Max
Top achievements
Rank 1
answered on 30 Nov 2011, 03:45 PM
hey Alex,

I eventually figurered the syntaxe but realized that would not work for my scenario.
ViewData is on the server and I needed to update the string on the Javascript side.
Anyways, my issue is described here:
http://www.telerik.com/community/forums/aspnet-mvc/general/is-this-possible-topic-loadcontentfrom.aspx

but since I am a beginner I still lack of some basic concepts. I think I need to learn more about JSON.
If at least I knew that what I am trying to do is possible that would make me happy.

Thanks for replying.

Max
Tags
Window
Asked by
Max
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Max
Top achievements
Rank 1
Share this question
or