我有一个登录局部视图,它正在引导模态中加载,在登录局部视图中,单击创建新链接后,我有一个创建新链接。
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>
这是我的登录局部视图,以下是我的
×
建立新帐户
<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");
}
但是,当我单击“新建”时,会在完整页面而不是模式内部打开注册视图。
最佳答案
也许你可以做这样的事情,在模式att中直接加载部分直接
工作提琴
http://jsfiddle.net/NUCgp/1552/
关于javascript - 如何在MVC 4中将不同的局部 View 加载到引导模态,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27293326/