C# MVC5标识单击“注册”按钮不起任何作用
这是一个带有Identity web应用程序的MVC5实体框架。我正在尝试修复我的注册方法,它将创建我的用户。当我点击register时,什么都没有发生,我也没有任何错误。我甚至不知道从哪里开始寻找解决方案 我希望将图像中所示的以下属性 AccountsViewModel.csC# MVC5标识单击“注册”按钮不起任何作用,c#,asp.net-mvc,entity-framework,razor,C#,Asp.net Mvc,Entity Framework,Razor,这是一个带有Identity web应用程序的MVC5实体框架。我正在尝试修复我的注册方法,它将创建我的用户。当我点击register时,什么都没有发生,我也没有任何错误。我甚至不知道从哪里开始寻找解决方案 我希望将图像中所示的以下属性 AccountsViewModel.cs public class RegisterViewModel { public int ID { get; set; } [Required] [EmailAddress] [Displ
public class RegisterViewModel
{
public int ID { get; set; }
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
public string FirstMidName { get; set; }
public string LastName { get; set; }
public string UserName { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime EnrollmentDate { get; set; }
public int DepotID { get; set; }
public IEnumerable<SelectListItem> DepotList { get; set; }
public IEnumerable<SelectListItem> DepartmentList { get; set; }
public int DepartmentID { get; set; }
}
公共类RegisterViewModel
{
公共int ID{get;set;}
[必需]
[电邮地址]
[显示(Name=“电子邮件”)]
公共字符串电子邮件{get;set;}
[必需]
[StringLength(100,ErrorMessage={0}的长度必须至少为{2}个字符。”,MinimumLength=6)]
[数据类型(数据类型.密码)]
[显示(Name=“密码”)]
公共字符串密码{get;set;}
[数据类型(数据类型.密码)]
[显示(Name=“确认密码”)]
[System.ComponentModel.DataAnnotations.Compare(“密码”,ErrorMessage=“密码和确认密码不匹配”。)]
公共字符串ConfirmPassword{get;set;}
公共字符串FirstMidName{get;set;}
公共字符串LastName{get;set;}
公共字符串用户名{get;set;}
[数据类型(DataType.Date)]
[DisplayFormat(DataFormatString=“{0:yyyy-MM-dd}”,ApplyFormatInEditMode=true)]
公共日期时间注册日期{get;set;}
public int DepotID{get;set;}
公共IEnumerable存储列表{get;set;}
公共IEnumerable部门列表{get;set;}
public int DepartmentID{get;set;}
}
AccountController.cs
public class AccountController : Controller
{
private ApplicationDbContext db = new ApplicationDbContext();
public AccountController()
{
}
public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager )
{
UserManager = userManager;
SignInManager = signInManager;
}
private ApplicationUserManager _userManager;
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}
// GET: /Account/Register
[AllowAnonymous]
public ActionResult Register()
{
RegisterViewModel model = new RegisterViewModel();
ConfigureRegisterViewModel(model);
ViewBag.DepartmentID = new SelectList(db.Departments, "DepartmentID", "DepartmentName");
ViewBag.DepotID = new SelectList(db.Depots, "DepotID", "DepotName");
return View(model);
}
//
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (!ModelState.IsValid)
{
ConfigureRegisterViewModel(model);
return View(model);
}
if (ModelState.IsValid)
{
var user = new ApplicationUser() {
UserName = model.UserName,
Email = model.Email,
FirstMidName = model.FirstMidName,
LastName = model.LastName,
EnrollmentDate = model.EnrollmentDate,
DepotID = model.DepotID,
DepartmentID = model.DepartmentID
};
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
ViewBag.Link = callbackUrl;
return View("DisplayEmail");
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
private void ConfigureRegisterViewModel(RegisterViewModel model)
{
IEnumerable<Department> departments = db.Departments.OrderBy(u => u.DepartmentName);
model.DepotList = departments.Select(a => new SelectListItem
{
Value = a.DepartmentID.ToString(),
Text = a.DepartmentName.ToString()
});
IEnumerable<Depot> depots = db.Depots.OrderBy(u => u.DepotName);
model.DepotList = depots.Select(a => new SelectListItem
{
Value = a.DepotID.ToString(),
Text = a.DepotName.ToString()
});
}
公共类AccountController:控制器
{
私有ApplicationDbContext db=新ApplicationDbContext();
公共账户控制员()
{
}
公共帐户控制器(ApplicationUserManager用户管理器、ApplicationSignInManager signInManager)
{
UserManager=UserManager;
SignInManager=SignInManager;
}
私有应用程序用户管理器\u用户管理器;
公共应用程序管理员用户管理器
{
得到
{
返回_userManager??HttpContext.GetOwinContext().GetUserManager”);
Link=callbackUrl;
返回视图(“显示电子邮件”);
}
加法器(结果);
}
//如果我们走到这一步,有些东西失败了,重新显示形式
返回视图(模型);
}
专用void配置RegisterViewModel(RegisterViewModel模型)
{
IEnumerable departments=db.departments.OrderBy(u=>u.DepartmentName);
model.DepotList=部门。选择(a=>new SelectListItem
{
Value=a.DepartmentID.ToString(),
Text=a.DepartmentName.ToString()
});
IEnumerable depots=db.depots.OrderBy(u=>u.DepotName);
model.DepotList=depots.Select(a=>new SelectListItem
{
Value=a.DepotID.ToString(),
Text=a.DepotName.ToString()
});
}
}
Register.cshtml
model RecreationalServicesTicketingSystem.Models.RegisterViewModel
@{
ViewBag.Title = "Register";
}
<h2>@ViewBag.Title.</h2>
@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(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.PasswordFor(m => m.Password, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.FirstMidName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.FirstMidName, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.LastName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.LastName, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.EnrollmentDate, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.EnrollmentDate, new { @class = "form-control" })
</div>
</div>
<div class="editor-field">
@using (Html.BeginForm())
{
@Html.HiddenFor(m => m.ID)
<div class="form-group">
@Html.LabelFor(m => m.DepotID, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.DropDownListFor(m => m.DepotID, Model.DepotList, "Please select", new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.DepartmentID, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.DropDownListFor(m => m.DepartmentID, Model.DepartmentList, "Please select", new { @class = "form-control" })
</div>
</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>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
模型娱乐服务SticketingSystem.Models.RegisterViewModel
@{
ViewBag.Title=“寄存器”;
}
@ViewBag.Title。
@使用(Html.BeginForm(“Register”、“Account”、FormMethod.Post、new{@class=“form horizontal”、role=“form”}))
{
@Html.AntiForgeryToken()
创建一个新帐户。
@Html.ValidationSummary(“,new{@class=“text danger”})
@LabelFor(model=>model.UserName,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.UserName,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.UserName,“,new{@class=“text danger”})
@LabelFor(m=>m.Email,新的{@class=“col-md-2控制标签”})
@TextBoxFor(m=>m.Email,新的{@class=“form control”})
@LabelFor(m=>m.Password,新的{@class=“col-md-2控制标签”})
@Html.PasswordFor(m=>m.Password,新的{@class=“form control”})
@LabelFor(m=>m.ConfirmPassword,新的{@class=“col-md-2控制标签”})
@Html.PasswordFor(m=>m.ConfirmPassword,new{@class=“form control”})
@LabelFor(m=>m.FirstMidName,新的{@class=“col-md-2控制标签”})
@TextBoxFor(m=>m.FirstMidName,新的{@class=“form control”})
@LabelFor(m=>m.LastName,新的{@class=“col-md-2控制标签”})
@TextBoxFor(m=>m.LastName,新的{@class=“form control”})
@LabelFor(m=>m.EnrollmentDate,新的{@class=“col-md-2控制标签”})
@TextBoxFor(m=>m.EnrollmentDate,新的{@class=“form control”})
@使用(Html.BeginForm())
{
@Html.HiddenFor(m=>m.ID)
@LabelFor(m=>m.DepotID,新的{@class=“col-md-2控制标签”})
@DropDownListFor(m=>m.DepotID,Model.DepotList,“请选择”,新建{@class=“form control”})
@LabelFor(m=>m.DepartmentID,新的{@class=“col-md-2控制标签”})
@DropDownListFor(m=>m.DepartmentID,Model.DepartmentList,“请选择”,新建{@class=“form control”})
}
}
@节脚本{
@Scripts.Render(“~/bundles/jquery
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
@using (Html.BeginForm())