在视图文件中使用asp-route-前缀来设置href的URL路径参数。例如:
Link
使用asp-route-前缀能够自动生成正确的URL路径,避免由于手动编写URL路径参数而出现的错误。同时,确保在app.UseMvc()中启用路由。
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}