AutoCrudAdmin 1.1.30
dotnet add package AutoCrudAdmin --version 1.1.30
NuGet\Install-Package AutoCrudAdmin -Version 1.1.30
<PackageReference Include="AutoCrudAdmin" Version="1.1.30" />
paket add AutoCrudAdmin --version 1.1.30
#r "nuget: AutoCrudAdmin, 1.1.30"
// 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
- Installation
- Usage
- Customization
- Navigation Menu
- Changing Layout
- Authentication
- Handling Files
- Overriding Views
- Customizing AutoCrudAdminController
- Troubleshooting
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
Call
services.AddAutoCrudAdmin()
inConfigureServices()
inStartup.cs
.Call
app.UseAutoCrudAdmin()
inConfigure()
inStartup.cs
.You have CRUD views and operations for each entity in your DbContexts.
You can customize the default behavior by creating a controller that inherits from
AutoCrudAdminController<TEntity>
whereTEntity
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.
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.
Navigation Menu
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 | Versions 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. |
-
net6.0
- Microsoft.EntityFrameworkCore (>= 6.0.0)
- NonFactors.Grid.Core.Mvc6 (>= 6.2.4)
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,620 | 12/7/2023 |
1.1.29 | 324 | 11/10/2023 |
1.1.28 | 169 | 10/31/2023 |
1.1.27 | 153 | 10/23/2023 |
1.1.26 | 740 | 7/6/2023 |
1.1.25 | 200 | 7/3/2023 |
1.1.24 | 230 | 6/14/2023 |
1.1.23 | 182 | 6/7/2023 |
1.1.22 | 234 | 6/6/2023 |
1.1.21 | 204 | 5/29/2023 |
1.1.20 | 198 | 5/26/2023 |
1.1.19 | 559 | 12/20/2022 |
1.1.18 | 655 | 9/14/2022 |
1.1.17 | 572 | 9/14/2022 |
1.1.16 | 698 | 3/7/2022 |
1.1.15 | 612 | 2/23/2022 |
1.1.14 | 617 | 2/14/2022 |
1.1.13 | 649 | 2/14/2022 |
1.1.12 | 1,597 | 11/26/2021 |
1.1.11 | 401 | 11/23/2021 |
1.1.10 | 401 | 11/23/2021 |
1.1.9 | 427 | 11/17/2021 |
1.1.8 | 462 | 11/12/2021 |
1.1.7 | 480 | 11/8/2021 |
1.1.6 | 513 | 11/5/2021 |
1.1.5 | 514 | 11/5/2021 |
1.1.4 | 469 | 11/5/2021 |
1.1.3 | 466 | 11/5/2021 |
1.1.2 | 473 | 11/5/2021 |
1.1.1 | 486 | 11/5/2021 |
1.1.0 | 481 | 11/1/2021 |
1.0.1 | 454 | 11/1/2021 |
1.0.0 | 477 | 11/1/2021 |