0

基本的に、ヘッダーの上部にあるメニュー、メイン コンテンツ div、サイドバー div を含む 1 つのビューがあり、すべてのボタンが別のパーシャルビューをメイン コンテンツ div にインポートします。現在ロード中 (ロード時間を節約)

@{if (TempData["CurrentSideBar"] != "Standard") 
  {
      <script type="text/javascript">
      $('#sidebarmain').load('@Url.Action("Standard", "SideBar")', function () {
           $('#loadingAjaxs').hide(); $('#flubestext').show(); window.history.pushState(null, 'title', '/users/');
      })
      </script>
      TempData["CurrentSideBar"] = "Standard";
   }}

これとビューバッグを試してみましたが、機能しません。これは、ヘッダー ボタンからコンテンツ div に入る各メインのパーシャルビューの上部にあります。これが理にかなっていることを願っています

4

2 に答える 2

0

メイン ビューに Javascript 変数を追加します。

_standard = 0;

標準のサイドバーにこれを追加します:

_standard = 1;

このコードを変更してください:

    @{if (TempData["CurrentSideBar"] != "Standard") 
    {
      <script type="text/javascript">
      $('#sidebarmain').load('@Url.Action("Standard", "SideBar")', function () {
           $('#loadingAjaxs').hide(); $('#flubestext').show(); window.history.pushState(null, 'title', '/users/');
      })
      </script>
      TempData["CurrentSideBar"] = "Standard";
   }}

これで:

  <script type="text/javascript">
    $(document).ready(function(){
      if(_standard == 0){
         $('#sidebarmain').load('@Url.Action("Standard", "SideBar")', function () {
            $('#loadingAjaxs').hide(); $('#flubestext').show(); window.history.pushState(null,   'title', '/users/');
         })
         _standard = 1;
      }
    });
  </script>
于 2013-10-02T09:43:58.703 に答える