window content from PartialView gives jQuery not defined error

6 posts, 2 answers
  1. Scott
    Scott avatar
    28 posts
    Member since:
    May 2015

    Posted 01 Nov 2015 Link to this post

    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.

     

  2. Answer
    Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    347 posts

    Posted 02 Nov 2015 Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Scott
    Scott avatar
    28 posts
    Member since:
    May 2015

    Posted 02 Nov 2015 Link to this post

    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.

  5. Scott
    Scott avatar
    28 posts
    Member since:
    May 2015

    Posted 02 Nov 2015 Link to this post

    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?

  6. Answer
    Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    347 posts

    Posted 04 Nov 2015 Link to this post

    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
  7. Scott
    Scott avatar
    28 posts
    Member since:
    May 2015

    Posted 04 Nov 2015 in reply to Dimiter Topalov Link to this post

     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!

     

Back to Top
UI for ASP.NET MVC is VS 2017 Ready