菜单是PartialView局部视图,
_Layout.cshtml中通过@Html.Action("Navigation", "Common")引用,
为什么每次单击菜单还进入到控制层的CommonController/Navigation,不影响效率吗?
望大家指导一下,刚学MVC不久。
_Layout.cshtml代码
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>@ViewBag.Title</title> 5 <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> 6 <link href="@Url.Content("~/scripts/jquery.easyui/themes/default/easyui.css")" rel="stylesheet" type="text/css" /> 7 <link href="@Url.Content("~/scripts/jquery.easyui/themes/icon.css")" rel="stylesheet" type="text/css" /> 8 <script src="@Url.Content("~/scripts/jquery/jquery-1.8.3.min.js")" type="text/javascript"></script> 9 <script src="@Url.Content("~/scripts/jquery.easyui/jquery.easyui.min.js")" type="text/javascript"></script> 10 <script src="@Url.Content("~/scripts/jquery.easyui/locale/easyui-lang-zh_TW.js")" type="text/javascript"></script> 11 <script src="@Url.Content("~/scripts/common.js")" type="text/javascript"></script> 12 @RenderSection("head", required: true) 13 </head> 14 15 <body> 16 <div id="wrapper"> 17 @Html.Action("Navigation", "Common") 18 <div id="contents"> 19 @RenderBody() 20 </div> 21 </div> 22 </body> 23 </html>
Navigation.cshtml代码(部分):
<div id="header"> <div id="logo"><a href="/"><img src="/images/logo.png" alt="logo" width="180" height="35" border="0" /></a></div> <div id="menu"> <a id="mbKnowledge" class="easyui-menubutton" data-options="menu:'#mmKnowledge',iconCls:'icon-search'">新聞與知識</a> <a id="mbAbout" class="easyui-menubutton" data-options="menu:'#mmAbout',iconCls:'icon-help'">關於知識產權課</a> </div> <div id="mmKnowledge" style="width:150px;display:none;"> @foreach (var item in ViewBag.KnowledgeCategoryList) { <div data-options="href:'/Knowledge/Category/@item.Value'">@item.Text</div> } <div class="menu-sep"></div> <div data-options="href:'/Knowledge/Search'">高級檢索條件</div> @if (Session["IsAdmin"] != null) { <div class="menu-sep"></div> <div data-options="href:'/Knowledge/Add'">建立文章</div> } </div> <div id="mmAbout" style="width:150px;display:none;"> <div data-options="href:'/Home/About'">部門介紹</div> <div data-options="href:'/Home/Feedback'">建議反饋</div> </div> </div> </div>
你不想这样就用 iframe吧,或者ajax异步刷新,或者把导航的数据缓存起来。
加上缓存,不用频繁进到CommonController/Navigation读数据了
iframe怎么用呀
把Navigation里面的链接换成ajax的
每次点击菜单,都要向服务器发起请求,然后由CommonController/Navigation处理请求,这是正常的MVC处理流程,不存在效率问题
点菜单后,也就是加载页面了,但菜单还要重新加载还进到CommonController/Navigation读菜单数据。