我正在尝试创建当前网站的移动版本。我按照以下文章http://www.hanselman.com/blog/MakingASwitchableDesktopAndMobileSiteWithASPNETMVC4AndJQueryMobile.aspx中的步骤进行操作。出于某种原因,每当我在ElectricPlum模拟器中打开网站时,我只会在开发人员工具控制台中获得.ui-loading屏幕和以下两个错误
未捕获的TypeError:无法读取属性'长度'未定义的 未捕获的TypeError:无法调用方法'替换'未定义的
我真的不明白这是怎么可能的,因为我现在拥有的是默认生成的_Laout.Mobile和一个名为Index.Mobile的主页,它只有
以下是我的Layou.Mobile.cshtml
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/Mobile/css", "~/Content/jquerymobile/css")
@Scripts.Render("~/bundles/jquery", "~/bundles/jquerymobile")
<script>
$(document).ready(function () {
$.mobile.ajaxEnabled = false;
});
</script>
</head>
<body>
<div data-role="page" data-theme="b">
@Html.Partial("_ViewSwitcher")
<div data-role="header">
<h1>@ViewBag.Title</h1>
</div>
<div data-role="content">
@RenderSection("featured", false)
@RenderBody()
</div>
</div>
</body>
</html>
_ViewSwitcher.cshtml
@if (Request.Browser.IsMobileDevice && Request.HttpMethod == "GET")
{
<div class="view-switcher ui-bar-a">
@if (ViewContext.HttpContext.GetOverriddenBrowser().IsMobileDevice)
{
@: Displaying mobile view
@Html.ActionLink("Desktop view", "SwitchView", "ViewSwitcher", new { mobile = false, returnUrl = Request.Url.PathAndQuery }, new { rel = "external" })
}
else
{
@: Displaying desktop view
@Html.ActionLink("Mobile view", "SwitchView", "ViewSwitcher", new { mobile = true, returnUrl = Request.Url.PathAndQuery }, new { rel = "external" })
}
</div>
}
Index.Mobile.cshtml
@{
ViewBag.Title = "Index.Mobile";
Layout = "~/Views/Shared/_Layout.Mobile.cshtml";
}
<h2>Index.Mobile</h2>
<ul id="test" data-role="listview" data-filter="true">
<li>something</li>
<li>something</li>
<li>something</li>
</ul>