AutoCrudAdmin 1.1.30

dotnet add package AutoCrudAdmin --version 1.1.30
NuGet\Install-Package AutoCrudAdmin -Version 1.1.30
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="AutoCrudAdmin" Version="1.1.30" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AutoCrudAdmin --version 1.1.30
#r "nuget: AutoCrudAdmin, 1.1.30"
#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 AutoCrudAdmin as a Cake Addin
#addin nuget:?package=AutoCrudAdmin&version=1.1.30

// Install AutoCrudAdmin as a Cake Tool
#tool nuget:?package=AutoCrudAdmin&version=1.1.30

AutoCrudAdmin Documentation

Table of Contents

Overview

AutoCrudAdmin is a library that provides automatic CRUD (Create, Read, Update, Delete) screens and API endpoints for entity classes in an ASP.NET Core application.

Installation

Install the AutoCrudAdmin NuGet package in your ASP.NET Core project.

dotnet add package AutoCrudAdmin

Usage

  1. Call services.AddAutoCrudAdmin() in ConfigureServices() in Startup.cs.

  2. Call app.UseAutoCrudAdmin() in Configure() in Startup.cs.

  3. You have CRUD views and operations for each entity in your DbContexts.

  4. You can customize the default behavior by creating a controller that inherits from AutoCrudAdminController<TEntity> where TEntity is the entity class.

That's it! AutoCrudAdmin will automatically generate CRUD screens and API endpoints for the entities.

The CRUD screens will be available under /ControllerName like /Products, /Customers etc. The API endpoints will be at /ControllerName/Create, /ControllerName/Edit etc.

Customization

AutoCrudAdmin provides options to customize the generated CRUD screens and API behavior.

Customizing Grid

The grid view that lists entities on the Index screen can be customized by overriding methods in the controller.

For example, to explicitly show certain columns:

public class ProductsController : AutoCrudAdminController<Product>  
{

  protected override IEnumerable<string> ShownColumnNames => 
    new[] { "Name", "Price" };

}

To add a custom column:

protected override IEnumerable<CustomGridColumn<Product>> CustomColumns =>
  new[]     
  {        
    new CustomGridColumn<Product>      
    {         
      Name = "Discount",
      ValueFunc = p => p.CalculateDiscount().ToString("0.##") 
    }
  };

See Customizing Grid for more details and options.

Customizing Form Fields

Similarly, the forms for Create and Edit actions can be customized via methods like:

  • ShownFormControlNames
  • HiddenFormControlNames
  • ShownFormControlNamesOnCreate

For example:

protected override IEnumerable<string> HiddenFormControlNames {
  new[] { "Description" }   
};

Hides the Description field.

See Customizing Forms for more details and options.

GenerateFormControls Methods

The GenerateFormControls methods are the main way to customize the form fields on Create and Edit pages.

See the GenerateFormControls Methods section for details on customizing these methods.

Adding Custom Actions

Additional controller actions can be added and will show alongside the standard CRUD actions.

See Adding Custom Actions.

Validating Entities

To perform validation, override the EntityValidators method:

protected override IEnumerable<Func<Product, Product, ValidatorResult>> EntityValidators {

  (existing, updated) => {
    if (updated.Quantity < 0) {
      return ValidatorResult.Error("Invalid quantity"); 
    }
    return ValidatorResult.Success();
  }

}; 

See Validating Entities for more details.

Generate a menu with links to CRUD screens using the NavHelper:

@foreach (var item in NavHelper.GetNavItems()) {
  <li>
    <a asp-controller="@item">@item</a>
  </li>
}

Changing Layout

The default layout is _AutoCrudAdmin_Layout. To use a custom layout:

services.AddAutoCrudAdmin(options => {
  options.LayoutName = "_CustomLayout";
});

Authentication

Add authentication by providing IAutoCrudAuthFilter implementations:

options.Authorization.Add(new MyAuthFilter()); 

See Authentication for examples.

Handling Files

The FormFilesContainer class passes files from forms to API endpoints.

Files are available in AdminActionContext.Files.

See Handling Files for more details.

Overriding Views

Override default AutoCrudAdmin views by placing view files in:

/Views/AutoCrudAdmin/

Customizing AutoCrudAdminController

The AutoCrudAdminController base class has many virtual members that can customize CRUD behavior:

Customize Grid

Customize grid columns:

protected override IEnumerable<CustomGridColumn<TEntity>> CustomColumns {..}

Add row actions:

protected override IEnumerable<GridAction> CustomActions {..}

Customize Forms

Show/hide form fields:

protected override IEnumerable<string> ShownFormControlNames {..}   
protected override IEnumerable<string> HiddenFormControlNames {..}

See API Reference for full customization options.

Troubleshooting

Some common issues:

  • Ensure DbContext registered properly in ConfigureServices()
  • For navigation menu, controller must inherit from AutoCrudAdminController
  • Check for conflicts with other packages
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.

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.1.30 1,113 12/7/2023
1.1.29 283 11/10/2023
1.1.28 130 10/31/2023
1.1.27 115 10/23/2023
1.1.26 702 7/6/2023
1.1.25 168 7/3/2023
1.1.24 197 6/14/2023
1.1.23 148 6/7/2023
1.1.22 200 6/6/2023
1.1.21 158 5/29/2023
1.1.20 162 5/26/2023
1.1.19 525 12/20/2022
1.1.18 600 9/14/2022
1.1.17 531 9/14/2022
1.1.16 657 3/7/2022
1.1.15 574 2/23/2022
1.1.14 582 2/14/2022
1.1.13 617 2/14/2022
1.1.12 1,561 11/26/2021
1.1.11 362 11/23/2021
1.1.10 369 11/23/2021
1.1.9 397 11/17/2021
1.1.8 432 11/12/2021
1.1.7 448 11/8/2021
1.1.6 480 11/5/2021
1.1.5 473 11/5/2021
1.1.4 439 11/5/2021
1.1.3 434 11/5/2021
1.1.2 441 11/5/2021
1.1.1 455 11/5/2021
1.1.0 438 11/1/2021
1.0.1 417 11/1/2021
1.0.0 443 11/1/2021