【问题标题】:how to load different partial view to the bootstrap modal in mvc 4如何将不同的局部视图加载到 mvc 4 中的引导模式
【发布时间】:2014-12-04 11:48:44
【问题描述】:

我有一个登录部分视图,它正在加载到引导模式中,在登录部分视图中我有一个点击创建新链接的新链接。

div class="modal-header" style="background-color: gainsboro">
    <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" style="height: 300px">
    <form id="frmLogin" class="form-horizontal" role="form">
        <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
            <div class="col-sm-10">
                <input type="email" title="email" pattern="^[a-zA-Z0-9._+-]+@("@")[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$" class="form-control" id="inputEmail3" placeholder="Email"  style="width: 400px;" required>
            </div>
        </div>
        <div class="form-group ">
            <label for="inputPassword3" class="col-sm-2 control-label">Password</label>
            <div class="col-sm-10">
                <input type="password" class="form-control" id="inputPassword3" placeholder="Password" style="width: 400px;" required>
            </div>
        </div>
        <label id="lblInvalidUser" class="errorMessage">Invalid user Credential</label>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <div class="checkbox">
                    <label>
                        <input type="checkbox">
                        Remember me
                    </label>
                </div>
                <a class="anchor-horizontal " href="#">Forgot password</a>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button id="btnLogin" type="button" class="btn btn-danger">Sign in</button>
            </div>
        </div>
    </form>

</div>
<div class="modal-footer">
    <label style="margin: 40px;">Dont have an account  yet</label>
    @Html.ActionLink("Create a new one", "Register", "Home", null, new { @class = "anchor-horizontal pull-right modal-link" })
    @*<a class="anchor-horizontal pull-right" href="#">Create a new one</a>*@
</div>

这是我的登录部分视图,以下是我的 × 建立新帐户

    <form id="frmLogin" class="form-horizontal" role="form">

            <div class="form-group">
                <div class="editor-label">
                    @Html.LabelFor(model => model.USER_EMAIL, "Your Email", new { @class = "col-sm-2 control-label" })
                </div>
                <div class="col-sm-10 editor-field">
                    @Html.EditorFor(model => model.USER_EMAIL, new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.USER_EMAIL)
                </div>
            </div>

            <div class="form-group">
                <div class="editor-label">
                    @Html.LabelFor(model => model.USER_PASSWORD, "Choose Password", new { @class = "col-sm-2 control-label" })
                </div>
                <div class="col-sm-10 editor-field">
                    @Html.EditorFor(model => model.USER_PASSWORD, new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.USER_PASSWORD)
                </div>
            </div>

            <div class="form-group">
                <div class="editor-label">
                    @Html.LabelFor(model => model.USER_CONFIRMPASSWORD, "Confirm Password", new { @class = "col-sm-2 control-label" })
                </div>
                <div class=" col-sm-10 editor-field">
                    @Html.EditorFor(model => model.USER_CONFIRMPASSWORD, new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.USER_CONFIRMPASSWORD)
                </div>
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.USER_MOBILENO, "Your Mobile No", new { @class = "col-sm-2 control-label" })
            </div>
            <div class="col-sm-10 editor-field">
                @Html.EditorFor(model => model.USER_MOBILENO, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.USER_MOBILENO)
            </div>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button id="btnRegister" type="submit" class="btn btn-danger">Create My Account</button>
                </div>
            </div>
    </form>

</div>
<div class="modal-footer">
    @Html.ActionLink("Back to List", "Login","Home",null,new { @class = "anchor-horizontal pull-left"})
</div>

}

这是我的 js,它正在打开我的模态。

//open bootstrap modal
$('body').on('click', '.modal-link', function (e) {
    debugger;
    e.preventDefault();
    $(this).attr('data-target', '#basicModal');
    $(this).attr('data-toggle', 'modal');
});

//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 () {
    debugger;
    $('#basicModal').modal('hide');
});

//clear modal cache, so that new content can be loaded.
$('#basicModal').on('hidden.bs.modal', function () {
    debugger;
    $(this).removeData('bs.modal');
});

我的控制器操作方法是。

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

但是当我点击新建时,它会在一个完整的页面中而不是在模式内部打开注册视图。

【问题讨论】:

    标签: javascript css asp.net-mvc twitter-bootstrap


    【解决方案1】:

    也许你可以做这样的事情,在模态 att 中直接加载部分

    <a data-toggle="modal" href="http://fiddle.jshell.net/bHmRB/51/show/" data-target="#myModal">Click me !</a>
    
    <!-- Modal --> <div class="modal fade" id="myModal" 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">Modal title</h4>
    
                </div>
                <div class="modal-body"><div class="te"></div></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 --> </div> <!-- /.modal -->
    

    工作小提琴 http://jsfiddle.net/NUCgp/1552/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-16
      • 1970-01-01
      • 2013-06-14
      • 1970-01-01
      • 2015-04-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多