MvcStyle 2.0.1

dotnet add package MvcStyle --version 2.0.1
                    
NuGet\Install-Package MvcStyle -Version 2.0.1
                    
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="MvcStyle" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MvcStyle" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="MvcStyle" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MvcStyle --version 2.0.1
                    
#r "nuget: MvcStyle, 2.0.1"
                    
#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.
#:package MvcStyle@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MvcStyle&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=MvcStyle&version=2.0.1
                    
Install as a Cake Tool

MvcStyleFormComponents

A lightweight Razor component library that allows Blazor Server or MVC-integrated Razor components to use familiar MVC-style HTML form patterns — including method, action, controller, and automatic antiforgery support, plus a component that works like < a > tag.

📦 Installation

You can install the package via NuGet:

dotnet add package MvcStyle
  • In the Program.cs add the namespace MvcStyle.ServiceCollection

    • Write builder.Services.AddMvcStyle();
  • In the the folder or Project that you created your razor components

    • Create a file named _Imports.razor and write on the top "@using MvcStyle.Components" so all you razor file are aware of this namespace

✨ Features

✅ MVC-style < form > rendering with method, action, controller, and routeId

✅ MVC-style < a > rendering with action, controller, and (optional) routeId

✅ Automatically generates antiforgery tokens in the < form >

✅ Easy integration inside .cshtml or .razor views

✅ Customizable submit logic

🚀Usage Example

< FileForm method="post" action="SomeControllerAction" controller="Controller" routeId="@Model.Id">

<input name="Email" @bind="employee.Email" />
<button type="submit">Save</button>

< /FileForm>

< Nav action action="SomeControllerAction" controller="Controller" routeId="@Model.Id">

SomeText

< /Nav>

Notice: In the Nav tag, the routeId parameter is optional, it's used in case you want to call a controller that has an integer type parameter.

🛡️ Antiforgery Support

AntiForgeryMarkup = await AntiforgeryService.GenerateHiddenMarkupInput();

⚙️ How it works

  • This component is meant to integrate with traditional MVC-style controllers. On submission:

    • It generates a classic HTML form with a valid action URL (based on controller, action, and optional routeId)

    • It injects a hidden antiforgery token

    • When submitted, it performs a full-page POST to the corresponding controller action.

    • The controller must return a RedirectToAction to the cshtml that houses the component, to re-render the updated state

    • The form is submitted like a traditional form: there is no AJAX or JavaScript submission.

    • It can be used even with custom Endpoints

⚠️ Things to notice

  • The form performs a full page reload on submission

  • The controller action should return a RedirectToAction(), to the View that houses the component

  • Antiforgery token is included by default for safety so always use [ValidateAntiForgeryToken] above the HttpPost Controller Action. This way you can always use HttpPost and not HttpPut nor HttpPatch nor HttpDelete

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.1 74 7/4/2025
2.0.0 75 7/4/2025
1.0.3 130 7/3/2025
1.0.2 128 7/3/2025
1.0.1 128 7/3/2025
1.0.0 128 7/3/2025