Хотите реализовать раскрывающийся список в RegisterView, не могу понять, как это сделать. Я новичок в asp.net mvc5 и следую первому подходу к коду. У меня уже есть стол для офисов. Я перечислю всю свою кодировку. Я думаю (я не уверен) я должен инициализировать список, но не знаю, как это сделать и куда его поместить
Иметь модель Office.Cs
public class Office
{
public byte Id { get; set; }
public string Name { get; set; }
}
}
Модель идентичности
public IEnumerable<Office> Office { get; set; }
[Required]
public byte OfficeId { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
AccountViewModel.cs
public class RegisterViewModel
{
public OfficeViewModel OfficeViewModel { get; set; }
[Required]
[Display(Name = "Office")]
public byte OfficeId { get; set; }
AccountController.cs
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email, OfficeId= model.OfficeId};
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
// string 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 <a href=\"" + callbackUrl + "\">here</a>");
return RedirectToAction("Index", "Home");
}
AddErrors(result);
Регистрвиев.cshtml
<div class="form-group">
@Html.LabelFor(m => m.OfficeId)
@Html.DropDownListFor(m => m.OfficeId, new SelectList(Model.Office, "Id", "Name"), "Select", new { @class = "form-control" })
</div>