簡體   English   中英

模態視圖重新加載內容(Bootstrap MVC ASP.NET)

[英]Modal View Reload Content (Bootstrap MVC ASP.NET)

阿羅哈,我在ASP.NET MVC4應用程序中使用Bootstrap v3.3.6來使用模態視圖顯示彈出窗口。

我的模態示例:

<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>

要加載模態,我使用Html.ActionLink之類的

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

這會觸發我的_Layout頁面中的腳本:

<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並且工作得很好。 在同一視圖中打開一個模式之前,直到嘗試打開一個模式。 然后,我將發現模態包含與以前相同的數據。
嘗試以下所有建議后:
重新加載模式內容(Twitter引導程序)
我感覺到問題是#modal-container的重新裝滿。 鏈接是由腳本以正確的方式完成的,正如我可以通過chrome調試來說的那樣。
如果我重新加載整個頁面,模態視圖將接受新內容。 但是由於我使用選項卡(也依賴於Bootstrap),因此無法重新加載,因為我會放棄當前的選項卡選擇。

我是Web開發的新手,所以如果您有一些想法,那將是很棒的。

您可以使用

ModelState.Clear();

用於清除控制器中的模型狀態。

希望對您有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM