jQuery Mobile: Multi-Page Application with Separate Pages: Second Page not Getting Styled

jQuery Mobile: Multi-Page Application with Separate Pages: Second Page not Getting Styled

Hello.  We have a single page application with two views (essentially, a list of items and a details page for the selected item).  Both views are in separate html files, and we’re using sammy.js to transition/navigate between the pages.  Everything was working great until we tried to add jQuery Mobile to the mix.  Now, when we navigate to the second page (the details page), jQuery Mobile is not styling the page.

Our working app is not set up as described by jQuery Mobile’s multi-page template (i.e., having all page divs in the same html file and use their navigation system to load linked pages into the DOM via AJAX).  But, is it possible to have separate pages, use something other than jQuery Mobile’s navigation, and still have jQuery Mobile style the second page?  Or, is there a way to force jQuery Mobile to style the second page?

Here’s some code snippets that’ll hopefully help show what we’re doing.  (Note: We’re also using ASP.NET razor views.)

index.cshtml
<body>
    @RenderPage("Views/items.cshtml")
    @RenderPage("Views/item.cshtml")

    @Scripts.Render("~/bundles/jquery")
    <script>
        $(document).bind("mobileinit", function () {
            $.mobile.ajaxEnabled = false;
            $.mobile.hashListeningEnabled = false;
            $.mobile.pushStateEnabled = false;
            $.mobile.loader.prototype.options.text = "loading.  please wait...";
            $.mobile.loader.prototype.options.textVisible = true;
        });
    </script>
    @Scripts.Render("~/bundles/jquerymobile", ...)
</body>
















items.cshtml (this page gets loaded and rendered correctly)
<section id="items-view" class="view" data-role="page">
    <section data-role="header">
        ....
    </section>

    <section data-role="content">
        (navbars, ULs, LIs, etc. are here, with each LI a link to go to the details page)
    </section>

    <section data-role="footer">
        ....
    </section>
</section>













item.cshtml (this page gets loaded but NOT rendered correctly, there is no jQuery Mobile styling)
<section id="item-view" class="view" data-role="page">
    <section data-role="header">
        ....
    </section>

    <section data-role="content">
        (ULs, LIs, listboxes, textboxes, etc. are here)
    </section>

    <section data-role="footer">
        ....
    </section>
</section>













router.js (used to route between pages)
....
            navigateTo = function (url) {
                sammy.setLocation(url);  // url = #/items or #/item/1234
            },
....





In the js file for the item page, we’ve tried:

                var $page = $("#item-view");
                //$page.trigger("create");
                //$page.listview("refresh");
                //$page.page();  (this one kind of work but doesn’t style every object)
                //$page.page("refresh", true);





but haven’t got any thing to work correctly and completely.

So, again, given our situation, is there a way to have a jQuery Mobile multi-page app with actual separate physical files and have all pages get style correctly?  Or is there a programmatic way to force jQuery Mobile to style all pages correctly?

Thanks.