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

window content from PartialView gives jQuery not defined error

5 Answers 1028 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 02 Nov 2015, 03:44 AM

I have a window (apologies for bolding... seems easiest way to distinguish code given limited formatting options)

     @(Html.Kendo()
          .Window()
          .Name("UserPermissionsWindow")
          .Title("User Privileges")
          .Content("loading privlege settings...")
          .Iframe(true)
          .Draggable()
          .Resizable()
          .Visible(false))

 

opened by a button click from a grid row:

          columns.Command(com => com.Custom("Privileges")
                                    .Click("openUserPermissionsWindow"));​

 The click handler calls the window refresh button:

 <script type="text/javascript">
    function openUserPermissionsWindow(e) {
        e.preventDefault();
        // the dataitem retrieved here will have the field values that can subsitute in the template (I hope)
        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
        personId = dataItem.Person_ID; //will this work?????
        var wnd = $("#UserPermissionsWindow").data("kendoWindow");
        wnd.refresh({
            url: "UserPrivileges/" + personId, // what does this url need to look like?
            data: { id: personId }
        });
        wnd.center().open();
    }
</script>

And the action returns a partialview containing a treeview wrapper:

 
<b>yo 'sup?</b>
@( Html.Kendo()
       .TreeView()
       .DataTextField("Name")
       .Name("userModulePermissions")
       .Checkboxes(cbxConfig => cbxConfig.Enabled(true)
                                         .CheckChildren(true)
                                         .Name("checkedNodes"))
       .DataSource(d => d.Read(read => read.Action("PermissionsTree_Read",
                                                   "SettingsUsers",
                                                   new {
                                                           userId = Model
                                                       })))
      )

But I end up with javascript error:  ReferenceError: jQuery is not defined

This is "fixed" by putting the jquery (and kendo?) bundles at the top of the PARTIAL view:

 @Scripts.Render("~/bundles/jquery")

@Scripts.Render("~/bundles/kendo")​

But because this is a PartialView in a window on a page that already exists, shouldn't it be able to use the jquery library that is already on the page?

I don't think I should have to bundle jquery libraries on partial views.

Currently the jquery bundle is at top of layout page.

Please advise.

 

5 Answers, 1 is accepted

Sort by
0
Accepted
Dimiter Topalov
Telerik team
answered on 02 Nov 2015, 02:56 PM
Hi Scott,

Judging by the provided code, the Window is configured to create an iframe. Loading partial content in an iframe is likely to cause incorrect behavior due to missing scripts and stylesheets. Please refer to the Using Iframes documentation for a more detailed explanation.

My suggestion is to either load a full web page in the iframe, or remove the Window iframe and load the partial view with Ajax.

I hope this helps. Don't hesitate to contact us again if you need further assistance.

Regards,
Dimiter Topalov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Scott
Top achievements
Rank 1
answered on 02 Nov 2015, 04:52 PM

HI, thanks, that answer sounds like it is close to the issue, as it appears to be treating the window content as a separate page.

I do not want to do that -- I do not want an iframe.

I'll be looking at the documentation to see how to avoid that, but that would be my quick question now: what option do I set in the window widget so that it does not use an iframe.

0
Scott
Top achievements
Rank 1
answered on 02 Nov 2015, 05:03 PM

I found the .Iframe() setting for kendo().window().

 One thing I am confused about is that the doc you linked says "The Window creates an iframe for its content if the content URL contains a protocol, i.e. it is assumed that in this case the nested page resides on another domain. If the URL does not contain s protocol, the assumption is that it is a local URL that will load a partial view"

But I am not explicitly including a protocol.

Does the .refresh() method prefix a protocol onto the path by default?

0
Accepted
Dimiter Topalov
Telerik team
answered on 04 Nov 2015, 09:19 AM
Hello Scott,

The Kendo UI Window creates an iframe either when the content URL contains a protocol, or when explicitly set by the developer using .Iframe(true), as in your case.

The refresh() method does not prepend a protocol - it uses the URL in the same way, as it has been provided in the method arguments.

So unless I am missing something, if you remove the .Iframe(true) setting, the Window will not create an iframe and the jQuery instance from the main page will be used inside the Window.

Regards,
Dimiter Topalov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Scott
Top achievements
Rank 1
answered on 04 Nov 2015, 08:34 PM

 Thank you.  

Feel like an idiot.  I did not realize I had iframe(true) in my original sample (most of which was cut/paste from a demo) -- you even mentioned it in your first reply but I thought you were referring to a default behavior.  At some point it was deleted between my post & first answer.  Trying to do too many things at once.

Everything makes sense now as to the original questions.  Thanks again!

 

Tags
General Discussions
Asked by
Scott
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Scott
Top achievements
Rank 1
Share this question
or