如何实现mvc应用程序的清单缓存



我正在尝试为一个页面实现清单。我不知道如何实现清单,使用下面我实现的参考。但它不起作用。

http://www.codemag.com/Article/1112051.

我的疑问是:在本地实现manifest后,即使visualstudio没有处于调试模式,刷新页面后也应该显示页面对吗?这里没有显示。

请帮助如何在mvc中实现manifest。

这是我的代码:

主控制器:

public ActionResult Index()
        {
            Response.Cache.SetCacheability(
               System.Web.HttpCacheability.NoCache);
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
            return View();
        }
        public ActionResult Manifest()
        {
            Response.ContentType = "text/cache-manifest";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.Cache.SetCacheability(
                System.Web.HttpCacheability.NoCache);
            return View();
        }

Index.cshtml:

<html manifest="@Url.Action("Manifest", "Home")">
<head>
    <title></title>
    <link href="~/Content/kendo/2014.2.903/kendo.common.min.css" rel="stylesheet" />
    <link href="~/Content/kendo/2014.2.903/kendo.default.min.css" rel="stylesheet" />
    <link href="~/Content/kendo/2014.2.903/kendo.dataviz.min.css" rel="stylesheet" />
    <link href="~/Content/kendo/2014.2.903/kendo.dataviz.default.min.css" rel="stylesheet" />
<script src="~/Scripts/kendo/2014.2.903/jquery.min.js"></script>
    <script src="~/Scripts/kendo/2014.2.903/kendo.angular.min.js"></script>
    <script src="~/Scripts/kendo/2014.2.903/kendo.all.min.js"></script>
    <script src="~/Scripts/modernizr-2.6.2.js"></script>
</head>
<body>
    <div id="grid"></div>
    <button type="button" id="btnOfflineMode">Offline</button>
    <script>

        $("#grid").kendoGrid({
                        columns: [
             { field: "Name" },
    { field: "Age" },
            { field: "NewCol" }
            ],
            dataSource: [
                          { Name: "John Doe", Age: 33 }
            ],
            batch: true,

        }).on('focus', function (e) {
                        var offset = $(this).offset();
            var textarea = $("<textarea>");
                        textarea.css({
                position: 'absolute',
                opacity: 0,
                top: offset.top,
                left: offset.left,
                border: 'none',
                width: $(this).width(),
                height: $(this).height()
            })
            .appendTo('body')
            .on('paste', function () {

                setTimeout(function () {
                var value = $.trim(textarea.val());
                var grid = $("#grid").data("kendoGrid");
            var rows = value.split('n');
                    var data = [];
                    for (var i = 0; i < rows.length; i++) {
                        var cells = rows[i].split('t');
                        grid.dataSource.add({
                            Name: cells[0],
                            Age: cells[1],
                            NewCol: cells[2]
                        });
                    }
                });
            }).on('blur', function () {
            });
            setTimeout(function () {
                textarea.focus();
            });
        });
        $("#grid").attr("tabindex", -1).focus();
    </script>
</body>
</html>

Manifest.cshtml:

CACHE MANIFEST
# version 1
CACHE:
/
/Content/kendo/2014.2.903/kendo.common.min.css
/Content/kendo/2014.2.903/kendo.default.min.css
/Content/kendo/2014.2.903/kendo.dataviz.min.css
/Content/kendo/2014.2.903/kendo.dataviz.default.min.css
/Scripts/kendo/2014.2.903/jquery.min.js
/Scripts/kendo/2014.2.903/kendo.all.min.js
/scripts/modernizr-2.6.2.js

FALLBACK:
/events /events.htm
NETWORK:
*
@{
    Layout = null;
}

events.html:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Events</title>
    <link rel="Stylesheet" href="/Content/style.css"
          type="text/css" />
</head>
<body>
    <section>
        <h1>Events</h1>
        <p>
            The event listings are only available when
            you are connected to the internet.
            </p>
        <div id="version">Version 1</div>
    </section>
</body>
</html>

尝试在站点的根文件夹中创建文件site.maifest。并在你的html中引用它。像这个

<html manifest="site.manifest">

看起来创建_Layout.cshtml逻辑并在其中放置通用标记会更好。

我创造了一个一切都很好的例子。它在GitHub 上

相关内容

  • 没有找到相关文章

最新更新