私はエラーが発生しています: 'int'に 'GetEnumerator'のパブリック定義が含まれていないため、foreach文は 'int'型の変数では動作できません。getenumerator mvcのパブリック定義が存在するため、foreach文は 'int'型の変数に対しては機能しません。
public ActionResult RoleCreate()
{
userType type = new userType();
List<DomainView> EmpList = type.GetAllRoleModulesViews();
List<ViewRoleModules> modules = new List<ViewRoleModules>();
Role objBind = new Role();
objBind.DomainViews = EmpList;
foreach (DomainView emp in EmpList)
{
int modID = emp.DomainID;
foreach (ViewRoleModules mod in modID)
{
}
}
return View(objBind);
}
モジュール:
public class DomainView
{
[Key]
public int DomainID { get; set; }
public string DomainCode { get; set; }
public string DomainName { get; set; }
public int TabOrder { get; set; }
public string UserName { get; set; }
public int CreatedBy { get; set; }
public DateTime CreatedDate = DateTime.UtcNow;
public int ModifiedBy { get; set; }
public DateTime ModifiedDate = DateTime.UtcNow;
public bool IsChecked { get; set; }
public IEnumerable<DomainView> DomainViews { get; set; }
}
と
public class ViewRoleModules
{
[Key]
public int ModuleID { get; set; }
public int DomainID { get; set; }
public int ParentModuleID { get; set; }
public int CompanyTypeID { get; set; }
public string ModuleName { get; set; }
public string FolderName { get; set; }
public string Url { get; set; }
public int TabOrder { get; set; }
public string Style { get; set; }
public string Status { get; set; }
public string IsTab { get; set; }
public string ApprovalProcess { get; set; }
public int CreatedBy { get; set; }
public DateTime CreatedDate = DateTime.UtcNow;
public int ModifiedBy { get; set; }
public DateTime ModifiedDate = DateTime.UtcNow;
public string DomainName { get; set; }
public string RoleName { get; set; }
public int RoleID { get; set; }
public bool IsChecked { get; set; }
public IEnumerable<ViewRoleModules> ModuleViews { get; set; }
}
エラーメッセージはcです学習する。 modIDは整数であり、整数を反復することはできません。 –
私は 'ViewRoleModules'にID値を渡す必要があります@AndyG –
[ask]を読んで、あなたがしようとしているものの[mcve]を作成してください。これはXYの問題です。エンティティのリストがあり、それを別のエンティティなどにマップしたい場合、 'foreach(var x in someInt) 'はそれを実行しません。 – CodeCaster