Quick Start

This guide covers installation and basic setup for each supported endpoint type.


Installation

Install the package via your preferred package manager.

dotnet CLI
Package Manager Console (PMC)
dotnet add package AspNetConventions
Install-Package AspNetConventions

Requirements: .NET 8, .NET 9, or .NET 10 (.NET SDK)


Setup

MVC Controllers

Call .AddAspNetConventions() on the IMvcBuilder returned by .AddControllers() or .AddControllersWithViews():

// Program.cs
using AspNetConventions;

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddControllers()
    .AddAspNetConventions();   // ← Here

var app = builder.Build();

app.MapControllers();
app.Run();

Minimal APIs

Call .UseAspNetConventions() on the WebApplication to get a RouteGroupBuilder, then map your endpoints on the returned group.

// Program.cs
using AspNetConventions;

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

var api = app.UseAspNetConventions();   // ← Here

api.MapGet("/WeatherForecast/{City}", (string City) =>
    Results.Ok(new { City, ZipCode = 000 }));

app.Run();

Razor Pages

Call .AddAspNetConventions() on the IMvcBuilder returned by .AddRazorPages() or .AddControllersWithViews():

// Program.cs
using AspNetConventions;

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddRazorPages()
    .AddAspNetConventions();   // ← Here

var app = builder.Build();

app.MapRazorPages();
app.Run();

Enable Tag Helpers

To support standardized routing and property binding within your views, add the AspNetConventions directive to your _ViewImports.cshtml file.
This ensures that helper attributes like asp-for correctly map your C# properties to the transformed HTML name attributes:

// _ViewImports.cshtml
@addTagHelper *, AspNetConventions

How it works:
The Tag Helper automatically aligns your HTML forms with your selected casing style:

<!-- Input Source -->
<input asp-for="CityName" />

<!-- Generated Output (e.g., kebab-case) -->
<input name="city-name" id="CityName" type="text" value="" />

See Disabling Property Transformation If you need to maintain the original C# property names.