-1

시스템의 모든 사용자 목록을 생성하려고합니다. 기본 내장 인증을 사용하고 있습니다. 난 내 컨트롤러에서 올바른, 데이타베이스 컨텍스트를 사용하고 있습니까 : 지금은이내 asp mvc보기에서 사용할 모델

public class ApplicationUser : IdentityUser 
{ 
    [Required] 
    [MaxLength(50)] 
    public string email { get; set; } 

    [Required] 
    [StringLength(11, MinimumLength = 11)] 
    public string cellNo { get; set; } 

    [Required] 
    [MaxLength(50), MinLengthAttribute(3)] 
    public string firstName { get; set; } 

    [Required] 
    [MaxLength(50), MinLengthAttribute(3)] 
    public string lastName { get; set; } 

    public DateTime birthdate { get; set; } 

} 

public class ApplicationDbContext : IdentityDbContext<ApplicationUser> 
{ 
    public ApplicationDbContext() 
     : base("AuthenticationConnection") 
    { 
    } 
} 

라는 사용자가 컨트롤러를 만듭니다 :

public class UsersController : Controller 
{ 
    private User_Manager_Interface.Models.ApplicationDbContext userDb = new User_Manager_Interface.Models.ApplicationDbContext(); 

    // GET: /Users/ 
    public ActionResult Index() 
    { 
     return View(userDb.Users.ToList()); 
    } 
    } 

1 여기

내 정체성 모델 클래스입니다?

2 : 내보기에는 어떤 모델을 사용해야합니까? 나는 그것을 실행할 때 이 @model IEnumerable<User_Manager_Interface.Models.ApplicationDbContext> 그러나 그것은 나에게 오류를 제공합니다 : 오류가 다음과 같다 : 현재 나는 다음이

사전에 전달 모델 항목 유형 '이다 System.Collections.Generic.List 1[User_Manager_Interface.Models.ApplicationUser]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable 1 [User_Manager_Interface.Models.ApplicationDbContext] '.

+0

보기에 바인딩 된 모델과 전달중인 모델을 확인하십시오. –

답변

0

컨트롤러에서 ApplicationUser 목록보기로 전달합니다. 오류 메시지에서 언급 한 것과 동일합니다. 따라서보기에 사용자 목록을 처리하려면 적절한 유형을 사용해야합니다.

@model IEnumerable<User_Manager_Interface.Models.ApplicationUser> 
+0

아, 알겠습니다. 보기를 컨텍스트에 바인딩 할 수 없습니다. 그것은 모델 일 필요가 있습니다. – Zapnologica

+0

왜 내 모델은 지금 eror를 givign입니까? '@ Html.DisplayNameFor (model => model.firstName)'완전히 멈추었을 때 나는 어떤 옵션도 가지고 있지 않다. 그리고 모델에 표시 태그를 추가 했는가? – Zapnologica

0

보기 당신은 모델로 변환 할 수있는 유형을 분석 할 필요가

@model List<User_Manager_Interface.Models.ApplicationUser> 
+0

'사전에 전달 된 모델 항목의 형식은 'System.Collections.Generic.List'1 [User_Manager_Interface.Models.ApplicationUser]'이지만이 사전에는 'System.Collections.Generic.List'1 유형의 모델 항목이 필요합니다 [User_Manager_Interface.Models.ApplicationDbContext] '. – Zapnologica

+0

실수 ... 수정 된 답변 확인 – Nilesh

1

이보십시오.

List<User_Manager_Interface.Models.ApplicationUser>을 반환 했으므로이를 지원하는 모델을 설정해야합니다.

@model IList<User_Manager_Interface.Models.ApplicationUser> 
@model IEnumerable<User_Manager_Interface.Models.ApplicationUser> 
@model List<User_Manager_Interface.Models.ApplicationUser> 

위의 유형 중 하나는 작동해야합니다.

+0

제안한 3 가지 옵션의 차이점을 자세히 설명 할 수 있습니까? – Zapnologica