简体   繁体   English

打开部分视图按钮,单击内部的模态asp.net MVC?

[英]Open Partial View on button click inside a modal asp.net mvc?

    function SimpleAjaxCall() {
        $.ajax({
            url: "/Account/Register",
            success: function (result) {
                $("#modalsignupbody").html(result);
                $('#signup').modal({
                    backdrop: 'static',
                    keyboard: true
                }, 'show');
            }
        });
    }

BUTTON CALL: 按钮呼叫:

<button id="SignUpbtn" class="btn btn-warning" onclick="SimpleAjaxCall();">Sign Up</button>

MODAL: 模态:

  <div class="modal fade" id="signin" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Sign in</h4>
            </div>
            <div class="modal-body">


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

Its not working i am able to go inside the controller function but i am not getting any result in the below code: 它不起作用,我可以进入控制器功能,但是在以下代码中没有任何结果:

 success: function (result) {

My Controller: 我的控制器:

   [HttpGet]
    [AllowAnonymous]
    public ActionResult Register()
    {
        return PartialView("_Register");
    }

很明显,您收到某种错误,请尝试检查FireBug的“网络”选项卡或当前使用的任何其他工具。

Try this: 尝试这个:

[HttpGet]
    [AllowAnonymous]
    public ActionResult Register()
    {
        return PartialView("~/Views/Account/_Register.cshtml");
    }

if its in Views/Shared folder then: 如果它位于“视图/共享”文件夹中,则:

[HttpGet]
    [AllowAnonymous]
    public ActionResult Register()
    {
        return PartialView("~/Views/Sahred/_Register.cshtml");
    }

#modalsignupbody can not be found anywhere in your view and the id of the modal is #signup in the ajax call, but #signin in the view. 在您的视图中的任何地方都找不到#modalsignupbody,模态的ID在ajax调用中是#signup,但在视图中是#signin。 The html should be populated into "modal-content". html应该填充到“ modal-content”中。

Try: 尝试:

function SimpleAjaxCall() {
    $.ajax({
        url: "/Account/Register",
        success: function (result) {
            $("#modal-body").html(result);
            $('#signin').modal({
                backdrop: 'static',
                keyboard: true,
                show:     true
            });
        }
    });
}

Besides, there is no need to use an ajax call back when bootstrap can do it all for you. 此外,当引导程序可以为您完成所有操作时,无需使用ajax回调。 In your case though, you would need to return all the header/footer etc, or make use of a template. 但是,就您而言,您将需要返回所有页眉/页脚等,或使用模板。

For that you would use: 为此,您将使用:

$('#SignUpbtn').click(function (e) {
    $("#signin").modal({
            backdrop:   true,
            keyboard:   true,
            remote:     "/Account/Register",
            show:       true
    })

})

BUTTON CALL: 按钮呼叫:

<button id="SignUpbtn" type="button" class="btn btn-warning">Sign Up</button>

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

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