首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jquery移动多页MVC 4

jquery移动多页MVC 4
EN

Stack Overflow用户
提问于 2013-02-08 14:34:00
回答 1查看 1.3K关注 0票数 3

我只是尝试用jquery做一个简单的多页面,但是使用缓存(我认为)会搞砸它。

这是我的布局:_MobileSwipe.Mobile.cshtml

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width">
    <meta charset="utf-8" />
    <title>@ViewBag.Title </title>
    @Html.MetaAcceptLanguage()
    <script src="@Url.Content("~/Scripts/kendo/2012.3.1121/jquery.min.js")"></script>
    @Scripts.Render("~/bundles/jquerymobile")
    @Styles.Render("~/Content/Mobile/css")
    @Styles.Render("~/Content/jquerymobile/css")
</head>
<body>
    @RenderBody()
</body>
</html>


<script>
    $(document).ready(function () {
        $.ajaxSetup({ cache: false });

    });
</script>

这是我的观点:

代码语言:javascript
复制
 @model List<ExtremeOnline.Models.BookingDays>

@{
    ViewBag.Title = "Välj din tid";
    Layout = "~/Views/Shared/_MobileSwipe.Mobile.cshtml";
}

<div data-role="page" id="1" class="ui-page">
    page 1
</div>
<div data-role="page" id="2" class="ui-page">
    page 2
</div>

 <script>
        $('div.ui-page').live("swipeleft", function () {
            var nextpage = $(this).next('div[data-role="page"]');
            // swipe using id of next page if exists
            if (nextpage.length > 0) {
                $.mobile.changePage(nextpage, 'slide');
            }
        });
        $('div.ui-page').live("swiperight", function () {
            var prevpage = $(this).prev('div[data-role="page"]');
            // swipe using id of next page if exists
            if (prevpage.length > 0) {
                $.mobile.changePage(prevpage, 'slide', true);
            }
        });

    </script>

这里是表单

代码语言:javascript
复制
  @using (Html.BeginForm("SearchMobile", "Boka", FormMethod.Post))
            {
                <input class="searchbutton" id="searchBtn" data-ajax="false" type="submit" data-theme="b" value="Sök bokning" />
            }

        </div>

问题是,当我运行它时,我发送的帖子的页面布局被缓存并显示在源代码中。

为什么布局是缓存的?该怎么办呢?

EN

回答 1

Stack Overflow用户

发布于 2013-12-07 05:33:12

JQuery移动依赖于多个页面布局的页面事件。而不是使用$(document).ready()。使用此处列出的页面事件:http://api.jquerymobile.com/category/events/

然后,可以在mobile事件中禁用ajax导航。

代码语言:javascript
复制
$(document).on(“mobileinit”, function() { 
    $.mobile.ajaxEnabled = false; 
});

您还需要将data-ajax="false“属性移动到表单,而不是输入按钮。

代码语言:javascript
复制
@using (Html.BeginForm("SearchMobile", "Boka", FormMethod.Post, new {data_ajax="false"}))
{
    <input class="searchbutton" id="searchBtn" type="submit" data-theme="b" value="Sök bokning" />
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14774846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档