如何在mvc 4中将不同的局部视图加载到bootstrap模式

时间:2014-12-04 11:48:44

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

我有一个登录部分视图,它在bootstrap模式中加载,在登录部分视图中,我点击了创建新链接时创建了一个新链接。

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");
    }

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

1 个答案:

答案 0 :(得分:-1)

也许你可以做这样的事情,在modal 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/