小编Cod*_*ent的帖子

为什么脚手架没有按预期工作?

我正在尝试搭建脚手架,但出现以下错误:

运行所选代码生成器时出错:“没有为类型‘MvcProduct.Data.MvcProductContext’定义无参数构造函数。”

您可以在这里看到它的图像: 搭脚手架时出错

以下是我的MvcProductContext

using Microsoft.EntityFrameworkCore;
using MvcProduct.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MvcProduct.Data
{
    public class MvcProductContext : DbContext
    {
        public MvcProductContext(DbContextOptions<MvcProductContext> options)
            : base(options)
        {
        }

        public DbSet<Product> Product { get; set; }
    } 
Run Code Online (Sandbox Code Playgroud)

还有appsettings.json

 {
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "MvcProductContext": "Server=(localdb)\\mssqllocaldb;Database=MvcProductContext-1;Trusted_Connection=True;MultipleActiveResultSets=true"
  }
Run Code Online (Sandbox Code Playgroud)

ConfigureServices文件中的方法Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllersWithViews();

    services.AddDbContext<MvcProductContext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("MvcProductContext")));
}
Run Code Online (Sandbox Code Playgroud)

我还尝试在 …

c# model-view-controller entity-framework asp.net-mvc-scaffolding asp.net-core-mvc

5
推荐指数
1
解决办法
1314
查看次数

如何在 Visual Studio 2019 中向我的 WebAPI 项目添加 wwwroot 目录

我的印象是 wwwroot 目录不仅仅是一个普通文件夹。如何在 Visual Studio 2019 中将其添加到我的项目中?

我已将以下内容添加到 Startup.cs 文件中的 Configure 方法中:

app.UseDefaultFiles();
app.UseStaticFiles();
Run Code Online (Sandbox Code Playgroud)

现在我只需要添加 wwwroot 目录本身。 我的解决方案

我正在尝试为以下教程中的第 2 步执行此操作:https : //docs.microsoft.com/en-gb/aspnet/core/tutorials/web-api-javascript?view=aspnetcore-3.0

什么是 wwwroot 目录?只是一个普通文件夹还是其他什么?

c# asp.net-web-api visual-studio-2019

1
推荐指数
1
解决办法
1476
查看次数