下面是我的模型。我創建在MVC表下拉列表中,但我得到這個錯誤asp.net mvc dropdownlist綁定
public class UserRegisterModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
public IEnumerable<Role> Roles { get; set; }
public SelectList RoleSelectList { get; set; }
public Role Role { get; set; }
private List<Role> GetRoles()
{
List<Role> roles = new List<Role>();
roles.Add(new Role() { Value = "c", RoleCode = "Corporate" });
roles.Add(new Role() { Value = "d", RoleCode = "Divisional" });
roles.Add(new Role() { Value = "r", RoleCode = "Regional" });
roles.Add(new Role() { Value = "f", RoleCode = "Facility" });
roles.Add(new Role() { Value = "s", RoleCode = "Resource" });
return roles;
}
public UserRegisterModel()
{
this.Roles = GetRoles();
this.RoleSelectList = new SelectList(Roles, "Value", "RoleCode");
}
public IEnumerable<UserAccinfo> UserAccounts { get; set; }
}
public class UserAccinfo
{
public string accountno { get; set; }
public IEnumerable<Brand> Brands { get; set; }
public SelectList BrandSelectList { get; set; }
public Brand Brand { get; set; }
private List<Brand> GetBrands()
{
List<Brand> brands = new List<Brand>();
brands.Add(new Brand() { BrandValue = "c", BrandCode = "Corporate" });
brands.Add(new Brand() { BrandValue = "d", BrandCode = "Divisional" });
brands.Add(new Brand() { BrandValue = "r", BrandCode = "Regional" });
brands.Add(new Brand() { BrandValue = "f", BrandCode = "Facility" });
brands.Add(new Brand() { BrandValue = "s", BrandCode = "Resource" });
return brands;
}
public UserAccinfo()
{
this.Brands = GetBrands();
this.BrandSelectList = new SelectList(Brands, "BrandValue", "BrandCode");
}
}
public class Brand
{
public string BrandCode { get; set; }
public string BrandValue { get; set; }
}
public class Role
{
public string RoleCode { get; set; }
public string Value { get; set; }
}
我如何可以綁定在MVC視圖第二下拉列表?
您可以添加您收到的錯誤嗎? – glosrob
這是錯誤消息:方法'System.Web.Mvc.Html.SelectExtensions.DropDownListFor(System.Web.Mvc.HtmlHelper ,System.Linq.Expressions.Expression >,System.Collections.Generic.IEnumerable ,string,object)'不能從用法中推斷出來。嘗試明確指定類型參數。 –
user1913029
我正在做這樣的考慮: