G4mvc.Generator
1.0.4
See the version list below for details.
dotnet add package G4mvc.Generator --version 1.0.4
NuGet\Install-Package G4mvc.Generator -Version 1.0.4
<PackageReference Include="G4mvc.Generator" Version="1.0.4" />
<PackageVersion Include="G4mvc.Generator" Version="1.0.4" />
<PackageReference Include="G4mvc.Generator" />
paket add G4mvc.Generator --version 1.0.4
#r "nuget: G4mvc.Generator, 1.0.4"
#:package G4mvc.Generator@1.0.4
#addin nuget:?package=G4mvc.Generator&version=1.0.4
#tool nuget:?package=G4mvc.Generator&version=1.0.4
G4mvc
G4mvc is a source generator for ASP.NET Core MVC apps that creates strongly typed helpers that eliminate the use of literal strings in many places.
It is an improved re-implementation of R4MVC using a C# Source Generator because R4MVC lacks support for many newer language and MVC features.
Installation
Install the G4mvc and G4mvc.Generator NuGet packages.
To enable the use of the tag helpers for anchor and form tags, add the @addTagHelper *, G4mvc.TagHelpers
directive either in the view, or in the _ViewImports.cshtml to enable them globally.
If you want to use the IUrlHelper
and IHtmlHelper
Extension methods, add a using directive for G4mvc.Extensions
either in the view, or in the _ViewImports.cshtml to enable them globally.
It might be necessary to restart Visual Studio for these changes to take affect.
Use
Source Generation
In order for the code generation to work, the controller class has to derive from the Microsoft.AspNetCore.Mvc.Controller
class. Abstract classes will also be ignored. All Methods for which a routing helper should be generated, have to return Microsoft.AspNetCore.Mvc.IActionResult
, Microsoft.AspNetCore.Mvc.Infrastructure.IConvertToActionResult
or an implementation of either of these interfaces. For asyncronous controller actions, the task has to return one of these.
Examples:
public IActionResult Edit(EditViewModel viewModel)
public JsonResult Edit(EditViewModel viewModel)
public Task<IActionResult> Edit(EditViewModel viewModel)
public Task<JsonResult> Edit(EditViewModel viewModel)
public IConvertToActionResult Edit(EditViewModel viewModel)
public ActionResult<IEnumerable<string>> Edit(EditViewModel viewModel)
Something like public IEnumerable<string> Edit(EditViewModel viewModel)
would be ignored.
Extensions
The G4mvc package provides a number of extension methods that can make using the generated route helpers a bit easier. You do however not have to rely on these because the G4mvcRouteValues
class derives from the standard Microsoft.AspNetCore.Routing.RouteValueDictionary
, so you can use any of the methods provided by ASP.net Core, that have an object routeValues
parameter. An example would be the HtmlHelper.RouteLink Method.
The provided extension methods are just wrappers for these methods.
Tag Helpers
G4mvc provides a TagHelper that can be used on anchor as well as form tags.
<a g4-action="MVC.Home.Index()">Home</a>
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- G4mvc (>= 1.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.