2016-04-13 15 views
2

アロハ、私は、モーダルビューを使用してポップアップを表示するために、ASP.NET MVC4アプリケーション内でブートストラップv3.3.6を使用しています。私のモーダルのためモーダルビューリロードコンテンツ(ブートストラップMVC ASP.NET)

例:

<div class="modal-contents modal-view content-wrapper"> 
    <div class="modal-header"> 
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
    </div> 
    <div class="modal-body content-wrapper"> 
    </div> 
</div> 
<script type="text/javascript"> 
    $(function() { 
     $('#approve-btn').click(function() { 
      $('#modal-container').modal('hide'); 
     }); 
    }); 
</script> 

私は_layoutページに私のスクリプトをトリガ

@Html.ActionLink("SomeText", "SomeAction", "SomeController", null , new { @class="modal-link"}) 

ようHtml.ActionLinkを使用モーダルロードするには:

<script type="text/javascript"> 
    $(function() { 
     // Initialize modal dialog 
     // attach modal-container bootstrap attributes to links with .modal-link class. 
     // when a link is clicked with these attributes, bootstrap will display the href content in a modal dialog. 
     $('body').on('click', '.modal-link', function (e) { 
      e.preventDefault(); 
      $(this).attr('data-target', '#modal-container'); 
      $(this).attr('data-toggle', 'modal'); 
      console.log(this); 
     }); 
     // Attach listener to .modal-close-btn's so that when the button is pressed the modal dialog disappears 
     $('body').on('click', '.modal-close-btn', function() { 
      $('#modal-container').modal('hide'); 
     }); 
     //clear modal cache, so that new content can be loaded 

     $('.modal').on('hidden.bs.modal', function() { 
      $(this).removeData('bs.modal'); 
     }); 

     $('#CancelModal').on('click', function() { 
      return false; 
     }); 
    }); 
</script> 

をし、最後に私の_Layoutのプレースホルダー

<div id="modal-container" class="modal fade" tabindex="-1" role="dialog"> 
    <div class="modal-content modal-view"> 
    </div> 
</div> 

これはすべてこれに依存して設計されています:http://www.codeproject.com/Tips/826002/Bootstrap-Modal-Dialog-Loading-Content-from-MVC-Paとうまく機能しました。私がすでに同じビューで開いた後にモーダルを開こうとするまでは。それから私は前と同じデータを含むようにモーダルを見つけるでしょう。
すべての提案を試した後:
Reload content in modal (twitter bootstrap)
私は問題が#モーダルコンテナの補充であると感じました。 リンクは、私がChromeでデバッグすると言うように、スクリプトによって正しい方法で完了します。
ページ全体をリロードすると、モーダルビューは新しいコンテンツを受け入れます。 しかし、私は(ブートストラップにも依存している)タブを使用しているので、現在のタブ選択を失うので、再ロードはオプションではありません。

私はウェブ開発にはとても新しいので、いくつかのアイデアがあればうれしいでしょう。

+0

異なるモーダルがすでに開いている同じモーダルでモーダルを開こうとしているシナリオは何ですか?それはやや珍しいシナリオです。 –

+0

可能な複製:http://stackoverflow.com/questions/12286332/twitter-bootstrap-remote-modal-shows-same-content-everytime –

+0

それは私によってひどく記述されました。私はモーダルを閉じて親ビューから別のリンク(とデータ)を使ってそれを再び開くことを意味しました。 Webgridを表示していて、異なる詳細を表示しようとしています。 私は既にあなたが言った質問のほとんどの解決策を試しました。 しかし、私は予備のもののいくつかを探します。 –

答えて

-1

あなたのコントローラに明確なモデル状態のため

ModelState.Clear(); 

を使用することができます。

あなたのお役に立てば幸いです。

+0

**モーダル**モデル –

+0

いいえモデル番号 –

+0

彼の問題はModelStateとは関係ありません。彼の質問は、ブーストラップ法の動作に関するものです。 –