首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模式视图重新加载内容(Bootstrap MVC ASP.NET)

模式视图重新加载内容(Bootstrap MVC ASP.NET)
EN

Stack Overflow用户
提问于 2016-04-13 22:15:07
回答 1查看 1.3K关注 0票数 3

您好,我在ASP.NET MVC4应用程序中使用Bootstrap v3.3.6来使用模式视图显示弹出窗口。

我的模式示例:

代码语言:javascript
复制
<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,如下所示

代码语言:javascript
复制
@Html.ActionLink("SomeText", "SomeAction", "SomeController", null , new { @class="modal-link"})

这会触发我的_Layout页面中的脚本:

代码语言:javascript
复制
<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中的占位符

代码语言:javascript
复制
<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)

我有一种感觉,问题是重新填充了#modal container。这些链接是由脚本以正确的方式完成的,正如我可以通过在chrome中调试所说的那样。

如果我重新加载整个页面,模式视图将接受新内容。但是因为我使用标签(也依赖于Bootstrap),所以不能重新加载,因为我会丢失当前的标签选择。

我对web开发非常陌生,所以如果你有一些想法,那就太好了。

EN

回答 1

Stack Overflow用户

发布于 2016-04-13 22:22:58

您可以使用

代码语言:javascript
复制
ModelState.Clear();

用于清除控制器中的模型状态。

希望能对你有所帮助。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36601160

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档