UrlActionGenerator 0.1.0
See the version list below for details.
dotnet add package UrlActionGenerator --version 0.1.0
NuGet\Install-Package UrlActionGenerator -Version 0.1.0
<PackageReference Include="UrlActionGenerator" Version="0.1.0" />
paket add UrlActionGenerator --version 0.1.0
#r "nuget: UrlActionGenerator, 0.1.0"
// 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
.
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 | 10,894 | 1/26/2022 |
0.5.0 | 303 | 12/21/2021 |
0.4.0 | 745 | 5/15/2021 |
0.4.0-alpha.6 | 166 | 5/10/2021 |
0.4.0-alpha.5 | 171 | 5/3/2021 |
0.4.0-alpha.4 | 158 | 5/2/2021 |
0.4.0-alpha.1 | 165 | 4/22/2021 |
0.3.0 | 393 | 3/14/2021 |
0.2.1 | 356 | 3/5/2021 |
0.2.0 | 363 | 3/5/2021 |
0.1.0 | 387 | 2/21/2021 |