G4mvc 1.0.0
See the version list below for details.
dotnet add package G4mvc --version 1.0.0
NuGet\Install-Package G4mvc -Version 1.0.0
<PackageReference Include="G4mvc" Version="1.0.0" />
<PackageVersion Include="G4mvc" Version="1.0.0" />
<PackageReference Include="G4mvc" />
paket add G4mvc --version 1.0.0
#r "nuget: G4mvc, 1.0.0"
#:package G4mvc@1.0.0
#addin nuget:?package=G4mvc&version=1.0.0
#tool nuget:?package=G4mvc&version=1.0.0
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 a re-implementation of R4MVC using a C# Source Generator.
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>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.AspNetCore.Mvc.ViewFeatures (>= 2.2.0)
- Microsoft.AspNetCore.Razor (>= 2.2.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on G4mvc:
Package | Downloads |
---|---|
G4mvc.Generator
A source generator for ASP.NET Core MVC apps that creates strongly typed helpers that eliminate the use of literal strings for routing |
GitHub repositories
This package is not used by any popular GitHub repositories.