RazorForms 1.0.0-beta6

This is a prerelease version of RazorForms.
There is a newer version of this package available.
See the version list below for details.
dotnet add package RazorForms --version 1.0.0-beta6                
NuGet\Install-Package RazorForms -Version 1.0.0-beta6                
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="RazorForms" Version="1.0.0-beta6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RazorForms --version 1.0.0-beta6                
#r "nuget: RazorForms, 1.0.0-beta6"                
#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 RazorForms as a Cake Addin
#addin nuget:?package=RazorForms&version=1.0.0-beta6&prerelease

// Install RazorForms as a Cake Tool
#tool nuget:?package=RazorForms&version=1.0.0-beta6&prerelease                

RazorForms

A simple ASP.NET Core library to simplify composing forms in Razor Pages

For most websites, a solution like Razor Pages works really well. It's fairly straightforward to use, and it offers power and flexibility. However, composing forms with Razor Pages is hot garbage.

Creating reusable UI elements is a breeze using partials and view components, and the built-in tag helpers make working with forms pretty straightforward. But it's not immediately obvious how to create reusable form UI while taking advantage of Razor Pages features like automatic value binding. Creating a simple registration form in Razor Pages using Bootstrap 5 looks something like this:

<form asp-page="/Registration"
      method="post">
    <div class="mb-3">
        <label asp-for="Username"
               class="form-label">
            Username
        </label>
        <input asp-for="Username"
               class="form-control"/>
        <span asp-validation-for="Username" class="text-danger"></span>
    </div>
    <div class="mb-3">
        <label asp-for="Email"
               class="form-label">
            Email address
        </label>
        <input asp-for="Email"
               class="form-control"/>
        <span asp-validation-for="Email" class="text-danger"></span>
    </div>
    <div class="mb-3">
        <label asp-for="Password"
               class="form-label">
            Password
        </label>
        <input asp-for="Password"
               class="form-control"/>
        <span asp-validation-for="Password" class="text-danger"></span>
    </div>
    <div class="mb-3">
        <label asp-for="PasswordConfirm"
               class="form-label">
            Confirm password
        </label>
        <input asp-for="PasswordConfirm"
               class="form-control"/>
        <span asp-validation-for="PasswordConfirm" class="text-danger"></span>
    </div>
    <button type="submit"
            class="btn btn-primary">
        Register
    </button>
    <button type="reset"
            class="btn btn-outline-secondary">
        Register
    </button>
</form>

As I said...hot. verbose. garbage.

You may be thinking of reaching for the trusty old SPA frameworks, because this is one of the problems they were designed to solve. But do you really need to create an entire SPA frontend just because your forms are a pain in the butt to compose?

Enter RazorForms

It doesn't have to be this way! You absolutely can create simple, straightforward websites that take advantage of all that Razor Pages has to offer without resorting to writing your entire frontend in JavaScript just because forms get repetitive.

The form shown above can be refactored using RazorForms:

<form asp-page="/Registration"
      method="post">
    <text-input asp-for="Username"/>
    <text-input asp-for="Email"/>
    <text-input asp-for="Password"/>
    <text-input asp-for="PasswordConfirm"/>
    <button type="submit"
            class="btn btn-primary">
        Register
    </button>
    <button type="reset"
            class="btn btn-outline-secondary">
        Register
    </button>
</form>

That's a reduction of almost 70% (47 lines vs. 15 lines with RazorForms). The correct input type is automatically detected in most cases, so all you usually need to do is pass the asp-for attribute with a reference to the model member the form field is for, just like with the built-in label and input tag helpers.

For more information on using RazorForms in a project, see the docs.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.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
1.0.0 581 12/28/2022
1.0.0-beta6 159 12/21/2022
1.0.0-beta5 129 12/19/2022
1.0.0-beta4 147 12/19/2022
1.0.0-beta3 130 9/28/2022
1.0.0-beta2 157 6/17/2022
1.0.0-beta1 161 6/17/2022

Minor bug fixes