0

Пытаюсь получить список пользователей в контроллере. Сначала пробовал так: введите сюда описание изображения

Попытался решить эту проблему (получить опции для создания контекста), получилось: введите сюда описание изображения

ApplicationDbContext.cs

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);
        // Customize the ASP.NET Identity model and override the defaults if needed.
        // For example, you can rename the ASP.NET Identity table names and more.
        // Add your customizations after calling base.OnModelCreating(builder);
    }
}
1

1 ответ 1

0

Имя "Configuration" не существует в текущем контексте

Это свойство находится в классе Startup (файл Startup.cs).

В этом классе в методе ConfigureServices(IServiceCollection services) зарегистрируйте ваш UserContext:

Startup.cs

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

    services.AddMvc();
}

HomeController.cs:

public class HomeController : Controller
{
    private readonly ApplicationDbContextcontext context;

    public HomeController (ApplicationDbContextcontext context)
    {
        this.context = context;
    }

    public IActionResult Index()
    {
        var users = context.Users.ToList();
        return View(users);
    }
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.