You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Core 2.2 Angular6项目运行报错:路由模板参数不完整

Fixing RoutePatternException in .NET Core 2.2 + Angular 6 Project

Hey there, let's work through this RoutePatternException you're facing. This error is pretty straightforward—it means somewhere in your route definitions, you’ve got an opening curly brace { that doesn’t have a matching closing }. Let’s start with your Startup.cs file (since you mentioned it) and cover all the likely spots to check.

1. Audit Route Templates in Startup.cs

First, jump to the Configure method in Startup.cs where you set up MVC routing. This is the most common place for this typo to creep in, especially if you made changes after generating the new app.

Example of a Broken Route

You might have a route definition like this (notice the missing closing } at the end):

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?"); // Missing closing } here!
});

Fixed Version

Just add the missing curly brace to fix the syntax:

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}"); // Closing } added
});

Also double-check any custom routes (like area routes or named routes) you added recently—copy-pasting or accidental edits often lead to missing braces here.

2. Check Attribute Routing in Controllers

If your Startup.cs looks clean, the next stop is your controller route attributes. Anytime you use [Route], [HttpGet], [HttpPost], etc., with route parameters, a missing } will trigger this error.

Example of a Broken Attribute Route

A controller method might have a typo like this:

[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
    // Missing closing } in the route template
    [HttpGet("details/{productId")]
    public IActionResult GetProductDetails(int productId)
    {
        // ...
    }
}

Fixed Version

Correct the attribute by adding the closing brace:

[HttpGet("details/{productId}")]
public IActionResult GetProductDetails(int productId)
{
    // ...
}

3. Compare with a Working Version

Since this started after generating another app, it’s possible you accidentally modified the original project’s routing code. If you use version control (like Git), compare your current Startup.cs and controller files with the last working commit—this will help you spot exactly which change caused the issue.

Quick Debugging Trick

If you’re still stuck, try commenting out sections of your routing config one by one (starting with any new routes you added) and running the project each time. This will help you isolate the exact route template that’s causing the error.

内容的提问来源于stack exchange,提问作者max

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:20:57