Click here to Skip to main content
15,887,385 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.

But the result is ,when i click the menus everytime ,the layout will render again,and the menu state will restore ,how to resolve the problem?



This is my code !!! Can anybody help me?Thanks!!!


XML
<!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>
Posted
Updated 22-May-12 21:33pm
v2

1 solution

Just put something like this in your view:
C#
@{ 
   Layout = Request.IsAjaxRequest() ? null : "~/Views/Shared/_Layout.cshtml"; 
}

Good luck!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900