且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

防止在MVC中重新加载布局页面中的菜单

更新时间:2023-12-02 11:09:46

您应该使用(.content)而不是(#content)

实施@Stephen答案:

Implementing @Stephen answer:

布局页面:

<script>
$(document).ready(function () {  
    //Select (AddCustomer) link specifically      
      $("#AddCustomer").click(function (e) {
        $('.content').load("/Customer/AddCustomer");
         return false;
      });
    }); 
</script>

<li class="treeview">
  <a href="#">
    <i class="fa fa-users"></i>
    <span>Customer</span>
  </a>
  <ul class="treeview-menu">
    <li><a id="ViewCustomer" href="/Customer/CustomerDetails"> <i class="fa fa-angle-double-right"></i>View Customer</a></li>
    <li><a id="AddCustomer" href="/Customer/AddCustomer"> <i class="fa fa-angle-double-right"></i>Add Customer</a></li>                       
  </ul>
</li>

<div class="content">
  @RenderBody()
</div>

在addcustomer操作方法中:

In addcustomer action method:

public ActionResult AddCustomer()
{
    return View("addcustomer");
}