当我从MVC视图页面的Controller文件夹中生成"新脚手架项目"时,我收到一条错误消息。
图像[
控制器文件夹
添加新的脚手架项目
添加带有视图的MVC控制器
错误代码";Microsoft Visual Studio";
]
这是我用过的模型。
public class Product
{
[Key]
public int ProductID { get; set; }
[Required (ErrorMessage = "Please enter a product name.")]
[StringLength(40)]
public int ProductName { get; set; }
[Required (ErrorMessage = "Please enter a product price.")]
[Column(TypeName = "decimal(8, 2)")]
public decimal Price { get; set; }
[Required (ErrorMessage = "Please enter a product Description.")]
public int Description { get; set; }
public byte [] Picture { get; set; }
public int StockID { get; set; }
public Stock Stock { get; set; }
[Required(ErrorMessage = "Please enter a product Category.")]
public int CategoryID { get; set; }
public Category Category { get; set; }
public string IdentityID { get; set; }
public IdentityUser Identity { get; set; }
}
应用程序.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook"
Version="3.1.12" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google"
Version="3.1.12" />
<PackageReference
Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore"
Version="3.1.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite"
Version="3.1.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer"
Version="3.1.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools"
Version="3.1.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers;
buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection"
Version="3.1.12" />
<PackageReference
Include="Microsoft.VisualStudio.Web.CodeGeneration.Design"
Version="3.1.5" />
</ItemGroup>
</Project>
这似乎是由于它们之间的版本不匹配,您可以如下修改Application.csproj
:
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="3.1.12" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="3.1.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.13" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.13" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.5" />
</ItemGroup>