// このコードは、Companytype の //IEnumerable 型のビューデータ項目がないというエラーを発生させます
//RegisterModel の現在のコード
public class RegisterModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[Display(Name = "Email Address")]
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[Required]
[Display(Name = "Company Name")]
public string CompName { get; set; }
[Required]
[Display(Name = "Company Type")]
public IEnumerable<SelectListItem> CompTypeList { get; set; }
[Required]
[Display(Name = "Total number of Branches")]
[Range(1,10,ErrorMessage = "The {0} must be at least {1}")]
public int TotalBranches { 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; }
}
//現在表示されているコード
<li>
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName)
</li>
<li>
@Html.LabelFor(m => m.Email)
@Html.TextBoxFor(m => m.Email)
</li>
<li>
@Html.LabelFor(m => m.CompName)
@Html.TextBoxFor(m => m.CompName)
</li>
<li>
@Html.LabelFor(m => m.CompTypeList)
@Html.DropDownList("Companytype","-select one-")
</li>
<li>
@Html.LabelFor(m => m.TotalBranches)
@Html.TextBoxFor(m => m.TotalBranches)
</li>
<li>
@Html.LabelFor(m => m.Password)
@Html.PasswordFor(m => m.Password)
</li>
<li>
@Html.LabelFor(m => m.ConfirmPassword)
@Html.PasswordFor(m => m.ConfirmPassword)
</li>
//AccountController プライベート DefaultDBEntities3 を登録 db = new DefaultDBEntities3();
[AllowAnonymous]
public ActionResult Register()
{
ViewBag.CompTypeList = new SelectList( "Companytype");
return View();
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
あなたの援助は大歓迎です