问题描述
迁移到asp.net core 2.2后,我的链接标记助手不再正常工作。
My link tag helpers are no longer working properly after migrating to asp.net core 2.2.
<a class="btn btn-outline-primary" asp-controller="MyController" asp-action="MyAction" asp-route-id="@Id">Link</a>
当我将兼容性版本设置为2.1时此方法很好,但当设置为兼容性时会生成一个空的href版本2.2。
This works fine when I set the compatibility version to 2.1, but produces an empty href when set to compatibility version 2.2.
<a class="btn btn-outline-primary" href="">Link</a>
我遵循了
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1); --> Works
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2); --> Doesn't work
项目文件无效:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TypeScriptToolsVersion>2.8</TypeScriptToolsVersion>
<LangVersion>7.2</LangVersion>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.2" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.1" />
<PackageReference Include="Sendgrid" Version="9.10.0" />
<PackageReference Include="Stripe.net" Version="22.8.1" />
<PackageReference Include="UAParser" Version="3.1.36" />
</ItemGroup>
<ItemGroup>
<Folder Include="Data\Migrations\" />
</ItemGroup>
</Project>
推荐答案
我今天在新的AspNet Core上遇到了同样的问题2.2使用内置的MVC模板创建的项目。标记不是在HTML中生成的。
I had the same issue today on a new AspNet Core 2.2 Project created using the built in MVC Template. The tags were not generated in the HTML.
更改以下
服务。 AddMvc()。SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
至
services.AddMvc()。SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
Works,这些标记现在在HTML中呈现,我进行了一些挖掘,看来这是 AspNetCore 2.2 中的一个问题。他们提到它已在 AspNetCore 3.0.0-preview3 中修复。
Works and the tags are now rendered in the HTML, I done some digging and it looks as though this has been raised as an issue in AspNetCore 2.2. They mention it has been fixed in AspNetCore 3.0.0-preview3.
如此处所述:和此处
如果需要使用AspNetCore 2.2,则可以采用临时解决方法,如果可行的话,请按照提出的问题在 Startup.cs
中修改以下内容。
If you need to use AspNetCore 2.2 then a temporary workaround, if viable is to ammend the following in your Startup.cs
as mentioned on the issue raised.
services.AddMvc(options => options.EnableEndpointRouting = false)
这篇关于链接标记帮助程序在ASP.NET Core 2.2中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!