Pages for a Model
izzy add crud creates a DataGrid page to display,
add, edit and delete a model's records (CRUD), for internal tools and admin screens. Name a class from your app; izzy
reads it from the source, so the app doesn't have to build first.
Add the page
izzy add crud Customer
This creates a page at /customers. The grid on it can search, sort and page the customers, and filters
its choice columns (an enum, a yes or no) from their headers. Add and Edit open a dialog that checks the form
against the model's attributes, and Delete asks before it deletes. A new customer's dates start at today.
The toolbar also has Columns and Export. Columns lets each person choose which columns to show, and remembers
the choice in a cookie. Export downloads the rows as an Excel file, from an endpoint in
Data/CustomerExport.cs.
It works on static pages and on interactive pages. When the app has accounts, the user must log in to open it.
Where the records are kept
The page loads and saves records through an ICustomerStore. If one of your DbContexts has a
DbSet<Customer>, the store uses it. Otherwise the records are kept in memory until the app
stops. To choose for yourself, set --store.
A second set of pages
The store, its interface and Data/CustomerExport.cs belong to the model, not to the pages. To give
a model a second set of pages, such as an admin grid beside the main one, run the command again with another
--name. The new set gets its own folder, route and nav link, and uses the store and export the
model already has.
izzy add crud Customer --name AdminCustomers --route admin/customers
Every set uses the same store, so the new set takes the model's store, and izzy stops if you ask for another
one. The export and the API check sign-in and policies for every set, so the new set needs the same
--authorize and policies as the first. To move all the sets to another store, run
one of the sets again with the new --store and --overwrite.
Labels and fields
Each field's label comes from [Display(Name)], or from the property's name split into words. A
column's title comes from ShortName.
The first column is the record's name: its first required text field, or a first and last name together, sorted by the last, with the first email under it. On a phone the grid keeps that column. The fields it's made from stay in the dialog, and Columns can show them on their own.
A DateTime or DateTimeOffset with a time is entered and shown in UTC, and its label
says so: "Opened (UTC)". To use another zone, give the field a TimeZone.
Some properties don't get a field: a key the database creates, read-only properties and computed ones. Related records, such as a customer's orders, aren't included either. izzy lists each property it leaves out.
A key people type in, such as an invoice number, needs the Pro pages. They ask for it when adding a record and show it read-only when editing.
Options
| Option | What it does |
|---|---|
--mode pages | Pro, planned. Creates separate pages to list, show and edit the records, for records with many fields. Without it, izzy creates one grid page that edits in a dialog. |
--name <Plural> | Sets the folder, the page names and the page title. Defaults to the model's plural, such as Customers. |
--singular <words> | Sets what one record is called on the page, when it isn't the class name. For example, --singular "team member" for a Member class. To set the plural, use --plural. |
--route <path> | Sets the page's URL. Defaults to the name in kebab case, such as customers. |
--folder <folder> | Sets the folder the page's own folder goes in, from the project's folder. Defaults to Components/Pages. |
--layout <Layout> | Names the layout component, such as EmptyLayout, when the page doesn't use the app's default. |
--render server | Runs the page over a circuit (@rendermode InteractiveServer). Without it, the page is static and works with no circuit. webassembly and auto need --store http. |
--nav false | Leaves the app's nav as it is. Without it, izzy adds a link to the page. |
--store ef|memory | Sets where the records are kept. ef needs a DbSet of the model. When two DbContexts have one, choose with --context. |
--store http | Pro, planned. For an app with a .Client project: writes the pages there and adds an API on the server for them to call. |
--authorize | Lets only signed-in people open the page. On by default when the app has accounts. |
--view-policy <name> | Lets only people the authorization policy allows open the page, such as ViewSales. |
--edit-policy <name> | Lets only people the policy allows add, edit and delete. Everyone else who can open the pages sees the records read-only. |
A page per task, with Pro
Planned
The grid page does everything in one place and edits in a dialog. With IzzyBlazor Pro, --mode pages
creates separate pages instead: a list with filters, a details page for each customer, and a form page that
lists its errors at the top. Records with many fields have more room on pages of their own.
The pages read the store on the server, so izzy doesn't add them to an app whose pages run in WebAssembly.
With IzzyBlazor Pro, --store http does, in any app with a .Client project. The
pages, ICustomerStore and an HttpCustomerStore go into the
.Client project. The server gets Data/CustomerApi.cs, an API at
/api/customers over the DbContext, or over memory when no DbContext has the model.
izzy add crud Customer --store httpIn the browser the grid's search, sort, filters and paging travel in the request's address, and the server runs them in the database. While the server draws the page first, it reads the server's store directly. The API asks for the same sign-in and policies as the pages. It sends only the fields the pages show, so a property izzy left out stays on the server. It checks what it is sent: the model's validation runs, and only the fields the form edits are saved.
The model class has to be in the .Client project, where the pages can see it. The server
project sees it there too. In an app whose pages are static by default, the pages get
@rendermode InteractiveAuto, or InteractiveWebAssembly when the app has no
server interactivity.
After the model changes
Run the command again with --diff to see what would change. Then run it with
--overwrite to update the files. See Previewing changes.