이 줄에 있습니다. '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