Action filled Tabs can't find scripts from partial views

5 posts, 1 answers
  1. Eric
    Eric avatar
    19 posts
    Member since:
    Mar 2014

    Posted 29 May 2014 Link to this post

    I have a TabStrip in the Index view for a controller:

    @{
        ViewBag.Title = "My Index";
    }
     
    <div id="portal" class="k-content">
        <div class="wrapper">
            @(Html.Kendo().TabStrip()
                .Name("tabstrip")
                .Items(tabstrip =>
                {
                    tabstrip.Add().Text("Information")
                        .Selected(true)
                        .LoadContentFrom("Information", "MyController");
     
                    tabstrip.Add().Text("Schedule")
                        .LoadContentFrom("Calendar", "MyController");
     
                    tabstrip.Add().Text("Plan")
                        .LoadContentFrom("Plan", "MyController");
     
                    tabstrip.Add().Text("Pending")
                        .LoadContentFrom("Pending", "MyController");
     
                })
            )
        </div>
    </div>
     
    @section Scripts{
     
    }



    And the initial level of 'Action' result is a view from the controller:

    For example, for the Plan action, the controller definition for that is:

    public ActionResult Information()
     {
       //get model data....
       model = blaw blaw
      return View("Information", model);
    }

    I return a View because then I can define a Layout file to load required javascript files. Somehow the tab has NO knowledge of the scripts loaded via the containing razor view of the TabStrip!

    My 'Information' view looks like a normal view with a specific minimal layout file to load scripts

    However, even with this manner of getting scripts to load, only the data-load scripts run. For example, the event scripts to handle the selected Kendo ComboBox item do not fire.

    The combo box is in a partial view loaded by the view (loaded in the tab): In the example below, the language combo box loads languages, but the Select event does not fire.

    @(Html.Kendo().ComboBox()
               .Name("languagesDdf")
               .Placeholder("Select Language...")
               .DataTextField("LanguageValue")
               .DataValueField("LanguageId")
               .Suggest(true)
               .AutoBind(false)
               .HtmlAttributes(new { style = "width: 100%" })
               .DataSource(source =>
               {
                   source.Read(read =>
                   {
                       read.Action("GetLanguages", "Language");
                   }).ServerFiltering(true);
               })
               .Events(e =>
               {
                   e.Select("onSelectLanguage");
               })
     
     
               )


    So why can't the tabs see scripts loaded by the parent razor view/layout files?

    Do I need to do something different with the tabstrip definition?


  2. Answer
    Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 02 Jun 2014 Link to this post

    Hi Robert,

    In current case you should return PartialView as the content is appended directly to the current DOM and loading more than once jQuery and KendoUI scripts will lead to unexpected behavior. 

    e.g.:
    public ActionResult Information()
     {
       //get model data....
       model = blaw blaw
      return PartialView("Information", model);
    }


    Regards,
    Vladimir Iliev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Eric
    Eric avatar
    19 posts
    Member since:
    Mar 2014

    Posted 12 Jun 2014 in reply to Vladimir Iliev Link to this post

    At the time, The Partial View had no access to any scripts loaded by the layout file that the partial view was loaded into.

    I reworked the scripts and it seems fine now.

    Oddly enough, If I load the exact same CSS and Script in the view via a bundles load instead, defined in App_Start\BundleConfig.cs, the kendo gadgetry fails to work... 
  5. Rob
    Rob avatar
    59 posts
    Member since:
    Jan 2012

    Posted 09 Apr 2015 Link to this post

    I have the exact same issue.

     Inside my Tabs (which are loaded from Views) I have a Telerik Grid , with a custom Command I am trying to link to a Javascript function. 'OnManage'

    columns.Command(Function(c) c.Custom("ManageMedia").Click("OnManage"))

    This fails as the Grid does not see the javascript function and it stops the grid from even loading.

     @Robert.. How did you 'rework the scripts' to allow the Telerik components inside the Tabs to see the functions?

     

    Many Thanks 

     

    Rob

  6. Rob
    Rob avatar
    59 posts
    Member since:
    Jan 2012

    Posted 12 Apr 2015 in reply to Rob Link to this post

    Came back to this after leaving for a few days.

     Very easy answer.. with a Partial View, you need to define the Javascript functions at the top of the view, so they are loaded first.

     All working now.. :)

     

    Rob

     

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