English 中文(简体)
如何不使天 提供每一次?
原标题:How do not make the _Layout render every time?

I created a test project of MVC3,and the project has only one layout of razor. In the Layout I use a jquery to create dynamic menus,I just want get the effect is when i clicked these menu ,it should return different partial views in the body segment,and the layout menu should remember the menu state i clicked on the layout page.

但结果是,当我每次点击菜单时, 版面布局将再次改变, 菜单状态将恢复, 如何解决问题?

这是我的密码! 有人能帮我吗?谢谢!

            <!DOCTYPE html>
            <html>
            <head>

                <title>@ViewBag.Title</title>
                <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
                <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
                <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
                <script type="text/javascript">
                    $(function () {
                              $(".sidebar1 dl dd").hide();
                              $(".sidebar1 dl dt").click(function () {
                              $(".sidebar1 dl dd").not($(this).next()).hide();

                              $(this).next().slideToggle(500);

                        });
                    });

            </script>

            </head>
            <body>
            <div class="container">
              <div class="header"><a href="#"><img src="/Content/images/logo.png" alt="logo" name="Insert_logo" width="180" height="90" id="Insert_logo" style="background-color: #C6D580; display:block;" /></a>

                <!-- end .header --></div>
              <div class="sidebar1">

                <dl class="nav">
                  <dt><a href="#">aaaaa</a></dt>
                    <dd>
                        <ul>
                      <li><a href="#">AAAA</a></li>
                          <li><a href="#">BBBB</a></li>
                          <li><a href="#">CCCC</a></li>

                        </ul>
                    </dd>
                  <dt><a href="#">aaaaa</a></dt>
                    <dd>
                        <ul>
                      <li><a href="#">AAAA</a></li>
                          <li><a href="#">BBBB</a></li>
                          <li><a href="#">CCCC</a></li>

                        </ul>
                    </dd>
               </dl>
            </div>
            <div class="content">

            @RenderBody()
            </div>

            </body>
            </html>
问题回答

you can specify the layout used on each page if needed. If you dont want a layout just set it to null. Put this at the top of the page:

@{
  layout = null
}

用户,

在下列情况中:

<div class="content">

您需要将此项修改为:

<div id="content">

然后您需要瞄准部分视图以更新 div 。 这意味着您的控制器动作应该返回部分视图 (), 而不是 View () 。 另外, 在不担心任何上述内容的情况下, 您可以尝试将您的点击功能修改为 :

$(function () {
    $(".sidebar1 dl dd").hide();
    $(".sidebar1 dl dt").click(function (e) {
        $(".sidebar1 dl dd").not($(this).next()).hide();

        $(this).next().slideToggle(500);
        e.preventDefault();
        return false;
    });
});

当你不显示ajax代码时,可能会有更多的要求,但我敢打赌,如果你在你的ajax电话中已经遵守了标准,那么,所有这一切都会解决上述变化。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签