// 此代码抛出一个错误,即没有类型的视图数据项 //IEnumerable for Companytype
//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);
}
您的帮助将不胜感激