UrlActionGenerator 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package UrlActionGenerator --version 0.1.0
NuGet\Install-Package UrlActionGenerator -Version 0.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UrlActionGenerator" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UrlActionGenerator --version 0.1.0
#r "nuget: UrlActionGenerator, 0.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UrlActionGenerator as a Cake Addin
#addin nuget:?package=UrlActionGenerator&version=0.1.0

// Install UrlActionGenerator as a Cake Tool
#tool nuget:?package=UrlActionGenerator&version=0.1.0

UrlActionGenerator

UrlActionGenerator is a C# Source Generator that assists the generation of URL's in ASP.NET Core projects and enforces the existance of a controller and method for the referenced URL.

Getting Started

To start using this package, simply add the UrlActionGenerator package to your ASP.NET Core project. After the package is installed, it will automatically find your controllers and add extension methods to the IUrlHelper class, which is available in Controllers and Razor views through the Url property.

Examples

How to use with a simple controller/action combo:

Controller:

public class HomeController : Controller
{
    public IActionResult Index()
    {
        return View();
    }
}

Usage:

Url.Actions().Home.Index()

Result:

/Home/Index

An action with parameters

Controller:

public class HomeController : Controller
{
    public IActionResult Search(int page, int pageSize = 20)
    {
        return View();
    }
}

Usage:

Url.Actions().Home.Search(1);
Url.Actions().Home.Search(2, pageSize: 50);

Result:

/Home/Search?page=1
/Home/Search?page=2&pageSize=50

Use with controllers in areas

Controller:

[Area("Admin")]
public class HomeController : Controller
{
    public IActionResult Index(string str)
    {
        return View();
    }
}

Usage:

Url.AdminActions().Home.Index("value");

Result:

/Admin/Home/Index?str=value

How it works

UrlActionGenerator is a C# Source Generator that runs as part of the compilation process. Every time your project is being compiled, the sources are passed into UrlActionGenerator which in turn uses these sources to search for controllers and actions.

When there are actions found in the project, a new generated class is added to the compilation with the extension methods on IUrlHelper.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.6.0 6,136 1/26/2022
0.5.0 273 12/21/2021
0.4.0 709 5/15/2021
0.4.0-alpha.6 153 5/10/2021
0.4.0-alpha.5 160 5/3/2021
0.4.0-alpha.4 143 5/2/2021
0.4.0-alpha.1 152 4/22/2021
0.3.0 361 3/14/2021
0.2.1 327 3/5/2021
0.2.0 332 3/5/2021
0.1.0 349 2/21/2021