[英]how to load different partial view to the bootstrap modal in mvc 4
I have a login partial view which is loading inside the bootstrap modal,in the login partial view i have a create new link on click of the create new link. 我有一个登录局部视图,它正在引导模态中加载,在登录局部视图中,单击创建新链接后,我有一个创建新链接。
div class="modal-header" style="background-color: gainsboro">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</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>
this is my login partial view and following is my × Create New Account 这是我的登录局部视图,下面是我的×创建新帐户
<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>
} }
this is my js which is opening my modal. 这是我的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');
});
and my controller action method is. 而我的控制器操作方法是
[HttpGet]
public ActionResult Register()
{
return PartialView("_register");
}
but when i click on the create new its opening the register view in a complete page rather than inside the modal. 但是,当我单击“新建”时,它会在完整页面而不是模态页面中打开注册视图。
Maybe you can do something like this, load partial direct in modal att 也许你可以做这样的事情,在模式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">×</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 -->
Workign fiddle http://jsfiddle.net/NUCgp/1552/ Workign小提琴http://jsfiddle.net/NUCgp/1552/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.