简体   繁体   English

在Bootstrap模式中渲染asp.net部分

[英]Render asp.net partial in Bootstrap modal

I need to display a partial (view component) in a bootbox control. 我需要在Bootbox控件中显示部分(视图组件)。 This partial receive some parameters from my current view and build a form to be submitted. 此部分从我当前的视图中接收一些参数,并构建要提交的表单。

Until MVC 5 I did that rendering my partial to a string and send it back to view. 在MVC 5之前,我一直将部分内容呈现为字符串并将其发送回视图。

In MVC 6 I can't get this to work. 在MVC 6中,我无法正常工作。

What is the correct way to do this? 正确的方法是什么?

After some research, I find out a way to do this, very easily. 经过一番研究,我很容易地找到了一种方法。 Just use the jquery's "load" function. 只需使用jquery的“加载”功能。 The example bellow is using default WebApplication created by VisualStudio. 下面的示例使用的是VisualStudio创建的默认WebApplication。

Main view code (Views/Home/About.cshtml): 主视图代码(Views / Home / About.cshtml):

<button class="btn btn-default details" >Click me</button>

<div class="modal" id="modal"></div>

@section scripts{
    <script>
        $(function () {
            $(".details").click(function () {
                $("#modal").load("Contact", function () {
                    $("#modal").modal();
                })
            });
        })
    </script>
}

Modal view code (Views/Home/Contact.cshtml): 模态视图代码(Views / Home / Contact.cshtml):

<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
            <h4 class="modal-title">Modal title</h4>
        </div>
        <div class="modal-body">
            <address>
                One Microsoft Way<br />
                Redmond, WA 98052-6399<br />
                <abbr title="Phone">P:</abbr>
                425.555.0100
            </address>

            <address>
                <strong>Support:</strong> <a href="mailto:Support@example.com">Support@example.com</a><br />
                <strong>Marketing:</strong> <a href="mailto:Marketing@example.com">Marketing@example.com</a>
            </address>

        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM