0
//此代碼thows了一個錯誤,有型的沒有可視數據項// IEnumerable的用於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分貝=新DefaultDBEntities3();
[AllowAnonymous]
public ActionResult Register()
{
ViewBag.CompTypeList = new SelectList("Companytype");
return View();
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
你的幫助,我將非常感激
//數據庫名DefaultDB // DBTABLE CoAdd // DBvar COID(標識)和Companytype 插入CoAdd值( '電信') INSERT INTO CoAdd值( '汽車') INSERT INTO CoAdd值(」政府') 插入到CoAdd值中('Banking' – vash363
您不需要將模型下拉列表添加到模型中,它們是在視圖中創建的,我想您要問的是,什麼樣的實體會支撐下拉列表。研究。這個論壇不是針對那種問題的。 –