Asp.net mvc 如何在不重定向的情况下从引导模式登录/注册?
我正在使用默认的web应用程序mvc项目,并尝试从modal登录/注册: 因此,我创建了一个新模型,其中包含用于登录和注册的模型Asp.net mvc 如何在不重定向的情况下从引导模式登录/注册?,asp.net-mvc,Asp.net Mvc,我正在使用默认的web应用程序mvc项目,并尝试从modal登录/注册: 因此,我创建了一个新模型,其中包含用于登录和注册的模型 public class LogInRegisterViewModel { public LoginViewModel login { get; set; } public RegisterViewModel register { get; set; } } 然后在我的布局页面中,我提供了该模型以及登录/注册的部分视
public class LogInRegisterViewModel
{
public LoginViewModel login { get; set; }
public RegisterViewModel register { get; set; }
}
然后在我的布局页面中,我提供了该模型以及登录/注册的部分视图:
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
@if (User.Identity.IsAuthenticated)
{
<li>@Html.ActionLink("MyUploads", "Index", "Tutorials")</li>
<li>@Html.ActionLink("Upload", "Create", "Tutorials")</li>
}
</ul>
@Html.Partial("_LoginPartial",model) @*model = new LogInRegisterViewModel()*@
</div>
@if(User.Identity.IsAuthenticated)
{
- @ActionLink(“我的上传”、“索引”、“教程”)
- @ActionLink(“上传”、“创建”、“教程”)
}
@Html.Partial(“_LoginPartial”,model)@*model=new LogInRegisterViewModel()*@
模式的html代码位于my _LoginPartial视图中(可能这是我的错误?),以及登录和注册表单(从帐户控制器复制):
@使用(Html.BeginForm(“Login”,“Account”,new{ReturnUrl=ViewBag.ReturnUrl},FormMethod.Post,new{@class=“form horizontal”,role=“form”}))
{
@Html.AntiForgeryToken()
使用本地帐户登录。
@Html.ValidationSummary(true,“,new{@class=“text danger”})
用户名
@TextBoxFor(m=>m.login.UserName,新的{@class=“form control”})
@Html.ValidationMessageFor(m=>m.login.UserName,“,new{@class=“text danger”})
密码
@Html.PasswordFor(m=>m.login.Password,新的{@class=“form control”})
@Html.ValidationMessageFor(m=>m.login.Password,“,new{@class=“text danger”})
@*为密码重置功能启用帐户确认后启用此选项
@ActionLink(“忘记密码?”,“放弃密码”)
*@
}
@使用(Html.BeginForm(“Register”、“Account”、FormMethod.Post、new{@class=“form horizontal”、role=“form”}))
{
@Html.AntiForgeryToken()
创建一个新帐户。
@Html.ValidationSummary(“,new{@class=“text danger”})
@LabelFor(m=>m.register.FirstName,新的{@class=“col-md-2控制标签”})
@TextBoxFor(m=>m.register.FirstName,新的{@class=“form control”})
@LabelFor(m=>m.register.LastName,新的{@class=“col-md-2控制标签”})
@TextBoxFor(m=>m.register.LastName,新的{@class=“form control”})
@LabelFor(m=>m.register.ProfileAvatar,新的{@class=“col-md-2控制标签”})
@TextBoxFor(m=>m.register.ProfileAvatar,新的{@class=“form control”})
@LabelFor(m=>m.register.Email,新的{@class=“col-md-2控制标签”})
@TextBoxFor(m=>m.register.Email,新的{@class=“form control”})
@LabelFor(m=>m.register.Password,新的{@class=“col-md-2控制标签”})
@Html.PasswordFor(m=>m.register.Password,新的{@class=“form control”})
@LabelFor(m=>m.register.ConfirmPassword,新的{@class=“col-md-2控制标签”})
@Html.PasswordFor(m=>m.register.ConfirmPassword,new{@class=“form control”})
<div class="modal fade" id="myModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content mc">
<div class="modal-body">
<div class="row">
<div class="col-md-6 login-modal">
<section id="loginForm">
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Use a local account to log in.</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
<div>
<h5 class="user-name login-labels"><i class="fa fa-user" aria-hidden="true"></i> User Name</h5>
</div>
<div class="col-md-8 login-input">
@Html.TextBoxFor(m => m.login.UserName, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.login.UserName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<h5 class="user-password login-labels"><i class="fa fa-lock" aria-hidden="true"></i> Password</h5>
<div class="col-md-8 login-input">
@Html.PasswordFor(m => m.login.Password, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.login.Password, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-10 login-btn">
<input type="submit" value="Log in" class="btn btn-primary" />
</div>
</div>
@* Enable this once you have account confirmation enabled for password reset functionality
<p>
@Html.ActionLink("Forgot your password?", "ForgotPassword")
</p>*@
}
</section>
</div>
<div class="col-md-6">
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Create a new account.</h4>
<hr />
@Html.ValidationSummary("", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(m => m.register.FirstName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.register.FirstName, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.register.LastName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.register.LastName, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.register.ProfileAvatar, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.register.ProfileAvatar, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.register.Email, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.register.Email, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.register.Password, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.PasswordFor(m => m.register.Password, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.register.ConfirmPassword, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.PasswordFor(m => m.register.ConfirmPassword, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Register" />
</div>
</div>
}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
@section scripts
{
@Scripts.Render("~/bundles/jqueryval")
}
<script src=".../Scripts/jquery.validate.js"></script>
<script src=".../Scripts/jquery.validate.unobtrusive.js"></script>