我的注册页面上有一个EnumDropDownListFor
控件,您可以从两个选项中进行选择。我尝试使用两个选项注册两个帐户,但两个帐户始终默认为第一个选项。
这在测试中以调试方式运行代码时始终有效,但是现在代码已在构建中,即使没有更改任何代码也不再起作用。
public enum RaceName
{
Terran,
AsphaMiner
}
// rest of file
<div class="form-group">
@Html.LabelFor(m => m.RaceName, new { @class = "col-md-2 control-label" })
<div class="col-md-6">
@Html.EnumDropDownListFor(m => m.RaceName, new { @class = "form-control" })
</div></div>
// more of file below too
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser
{
UserName = model.UserName,
Email = model.Email
RaceName = model.RaceName,
// rest of controller
public class ApplicationUser : IdentityUser
{
public RaceName RaceName { get; set; }
[NotMapped]
public Race PlayerRace { get; set; }
public ApplicationUser()
{
PlayerRace = new Race(this);
}
// rest of default code
public virtual ApplicationUser RaceOwner { get; set; }
public Race(ApplicationUser user)
{
RaceOwner = user;
}
// other properties with [NotMapped] attribute so
// static values are not saved to sql db
public class RegisterViewModel
{
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[Display(Name = "Username")]
public string UserName { 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")]
[Compare("Password", ErrorMessage = "The password and confirmation
password do not match.")]
public string ConfirmPassword { get; set; }
public RaceName RaceName { get; set; }
}
因此,用户创建了一个帐户,输入了用户名电子邮件密码等,然后从DropDownList
的2个选项中进行选择,但它始终选择第一个选项,并且在调试和构建之间我没有做任何更改版本。
如果我选择AsphaMiner
,它将设置为Terran
;并且如果我选择Terran
,则会将其设置为Terran
。
有人能推荐什么吗?