我 有 一 个 enum
, 我 想 将 其 转换 为 一 个 DropDownList
, 以便 注册 我 目前 正在 使用 的 :
@Html.DropDownListFor(InputModel => InputModel.Input.UserProffesion.GetValues(typeof(Mindfull8User.Proffesion)).Cast<string>())
中 的 每 一 个
我 收到 一 个 错误 :
严重 性 代码 描述 项目 文件 行 禁止 显示 状态 错误 ( active ) * * CS0176 * * 无法 使用 示例 引用 访问 成员 " * * Enum . GetValues ( Type ) * * " ;用 一 个 类型 名 来 代替 Mindfull8 来 限定 它
我 该 怎么 解决 这个 问题 ? 谢谢
数据 模型 :
namespace Mindfull8.Areas.Identity.Pages.Account
{
public class RegisterModel : PageModel
{
private readonly SignInManager<Mindfull8User> _signInManager;
private readonly UserManager<Mindfull8User> _userManager;
private readonly IUserStore<Mindfull8User> _userStore;
private readonly IUserEmailStore<Mindfull8User> _emailStore;
private readonly ILogger<RegisterModel> _logger;
private readonly IEmailSender _emailSender;
public RegisterModel(
UserManager<Mindfull8User> userManager,
IUserStore<Mindfull8User> userStore,
SignInManager<Mindfull8User> signInManager,
ILogger<RegisterModel> logger,
IEmailSender emailSender)
{
_userManager = userManager;
_userStore = userStore;
_emailStore = GetEmailStore();
_signInManager = signInManager;
_logger = logger;
_emailSender = emailSender;
}
/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
[BindProperty]
public InputModel Input { get; set; }
/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public string ReturnUrl { get; set; }
/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public IList<AuthenticationScheme> ExternalLogins { get; set; }
/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public class InputModel
{
[Required]
[StringLength(255, ErrorMessage = "Max characters is 255")]
[Display(Name = "FirstName")]
public string FirstName { get; set; }
[Required]
[StringLength(255, ErrorMessage = "Max characters is 255")]
[Display(Name = "LastName")]
public string LastName { get; set; }
[Required]
[Display(Name = "Gender")]
public bool? Gender { get; set; }
[Required]
[Display(Name = "Proffesion")]
public Proffesion UserProffesion{ get; set; }
/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
/// <summary>
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
}
}
格式Register.cshtml
:
<div class="row">
<div class="col-md-4">
<form id="registerForm" asp-route-returnUrl="@Model.ReturnUrl" method="post">
<h2>Create a new account.</h2>
<hr />
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-floating">
<input asp-for="Input.FirstName" class="form-control" autocomplete="username" name="FirstName" aria-required="true" />
<label asp-for="Input.FirstName">First Name</label>
<span asp-validation-for="Input.FirstName" class="text-danger"></span>
</div>
<div class="form-floating">
<input asp-for="Input.LastName" class="form-control" autocomplete="username" name="LastName" aria-required="true" />
<label asp-for="Input.LastName">Last Name</label>
<span asp-validation-for="Input.LastName" class="text-danger"></span>
</div>
<div class="form-floating">
<input asp-for="Input.Email" class="form-control" autocomplete="username" aria-required="true" />
<label asp-for="Input.Email"></label>
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
<div class="form-floating">
<input asp-for="Input.Password" class="form-control" autocomplete="new-password" aria-required="true" />
<label asp-for="Input.Password"></label>
<span asp-validation-for="Input.Password" class="text-danger"></span>
</div>
<div class="form-floating">
<input asp-for="Input.ConfirmPassword" class="form-control" autocomplete="new-password" aria-required="true" />
<label asp-for="Input.ConfirmPassword"></label>
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
</div>
<div class="form-floating">
@Html.DropDownListFor(InputModel=> InputModel.Input.UserProffesion , Html.GetEnumSelectList<Proffesion>(), optionLabel: "Select a value")
</div>
<div class="form-floating">
</div>
<button id="registerSubmit" type="submit" class="w-100 btn btn-lg btn-primary">Register</button>
</form>
格式
用户 模型 为 :
public class Mindfull8User : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime CreationDate { get; set; } = DateTime.Now;
public DateTime LastOnline { get; set; } = DateTime.Now;
public bool? Gender { get; set; }
public Proffesion UserProffesion { get; set; }
public enum Proffesion
{
Doctor,
Paitent,
Proffesor
}
}
格式
1条答案
按热度按时间vs91vp4v1#
是否尝试使用返回给定类型的选择列表的HtmlHelper.GetEnumSelectList Method?
例如,如果
Proffesion
是给定的enum
类型: