-1

システム内のすべてのユーザーのリストを生成しようとしています。デフォルトの組み込み認証を使用しています。

ここに私のアイデンティティモデルクラスがあります:

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.IEnumerable1[User_Manager_Interface.Models.ApplicationDbContext]' 型です。

4

3 に答える 3

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>

多くの可能性がありますが、上記のタイプのいずれかが機能するはずです。

于 2014-01-29T09:47:30.533 に答える
0

あなたの見解でこれを試してください

@model List<User_Manager_Interface.Models.ApplicationUser>
于 2014-01-29T09:42:44.537 に答える
0

コントローラーからビューに ApplicationUser のリストを渡します。エラーメッセージに記載されているものと同じです。したがって、ビューでユーザーのリストを処理するには、適切なタイプを使用する必要があります

 @model IEnumerable<User_Manager_Interface.Models.ApplicationUser>
于 2014-01-29T09:48:26.173 に答える