1

I have an application that I am developing with jquery.mobile (1.3.1) over asp.net 4.5.

The first page consists of a list, the selection of an item in that list leads to another page. I have developed the pages separately.

When I click one of the items in the list, the second page is shown correctly but the URL is incorrect. I believe this is because jquery.mobile is intercepting the link click and handling the page transition itself - I do not want this and would prefer the link to behave naturally.

  • The URL to the page in question: http://myhost/mobile
  • The URL I am linking to: http://myhost/mobile/NewClient.aspx
  • The URL shown: http://myhost/mobile/#/myhost/mobile/NewClient.aspx?ClientID...

The page list code:

  <div data-role="page" id="logon" data-theme="c">
    <div data-role="header" data-position="fixed">
      <h1>Select location</h1>
    </div>
    <div data-role="content">
      <asp:ListView ID="LocationList" runat="server"
        ItemType="AGP.BackOffice.Model.ClientSource"
        DataKeyNames="ID" SelectMethod="LocationList_SelectMethod"
        OnItemDataBound="LocationList_ItemDataBound">
        <LayoutTemplate>
          <ul data-role="listview" data-inset="false" data-divider-theme="b">
            <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
          </ul>
        </LayoutTemplate>
        <ItemTemplate>
          <li data-theme="c">
            <asp:HyperLink ID="HyperLink" runat="server" NavigateUrl="~/Mobile/NewClient.aspx?ClientSourceID={0}&IsMinimalDataCapture={1}"
                            data-transition="slide" Text="<%#: Item.Description %>" />
          </li>
        </ItemTemplate>
      </asp:ListView>
    </div>
  </div>

I have found various articles claiming that the built in page handling in jquery.mobile can be turned off as follows...

  <script type="text/javascript">
    $(document).bind("mobileinit", function () {
      $.mobile.ajaxEnabled = false;
      $.mobile.linkBindingEnabled = false;
    });
  </script>

I have added this before the data-role="page" div, however it makes no difference.

Can anybody shed any light on this? I just want the links to be handled as they are by the browser whilst still taking advantage of the jquery.mobile UI elements.

I should also point out that this behaviour is only seen on mobile devices (tested on WP8 & iPad). On the desktop, the URL seems to be fine.

Thanks.

4

1 回答 1

0

发现这个:JQuery Mobile Links with MVC

删除我的 JavaScript 并添加rel="external"到每个锚标记。它们现在按需要运行。

仍然有兴趣知道是否有更好的方法来解决这个问题。

于 2013-04-18T18:43:52.433 回答