Open danroth27 opened 1 year ago
Cool will keep track of this and see what items I can create for the upcoming .NET 8 preview 7.
The scaffolded content assumes static server rendering, but the app might be setup with an interactive router. We are still working through how we want to handle scenarios like this for .NET 8.
Ideally the scaffolded pages would work in either static SSR or InteractiveServer modes without any code changes. Since the same data access code would work both ways, this seems like it should be possible.
Of course, InteractiveWebAssembly is different because of forcing an API layer. I can certainly understand not wanting to support that in the short term.
The issue described in here prevents me from using the scaffolded ui, after updating to .net 8. Is there any new information available, for a possible static ssr support for the components? Or an alternative workaround? :)
The issue described in here prevents me from using the scaffolded ui, after updating to .net 8. Is there any new information available, for a possible static ssr support for the components? Or an alternative workaround? :)
@tjorvenK For a .NET 8 workaround, you can dynamically in code set the render mode of the router to be Static for specific request paths. It's not a pretty solution, but it is possible. The default identity UI included in the Blazor Web App template uses this technique when the app has global interactivity enabled. We plan to address this issue to provide a better solution in .NET 9.
@tjorvenK For a .NET 8 workaround, you can dynamically in code set the render mode of the router to be Static for specific request paths. It's not a pretty solution, but it is possible. The default identity UI included in the Blazor Web App template uses this technique when the app has global interactivity enabled. We plan to address this issue to provide a better solution in .NET 9.
@danroth27 Thank you for the quick answer, I found the example you mentioned and I am excited for .NET 9 !
This issue covers delivering scaffolders for building Razor components that are analogous to the existing scaffolders for Razor Pages and EF Core that exist today. These scaffolders are server specific and are generally not intended for client scenarios (Blazor WebAssembly or Blazor Hybrid). Admittedly this violates our principle that Blazor components should typically be hosting model agnostic. But the alternative is to generate components based on a custom data access abstraction that has implementations for both server and client including any required server API endpoints, which would be non-trivial.
Starting with an existing entity model class, there are two scaffolders to select from:
The CRUD scaffolder is a shorthand for creating pages for all five templates (Create, Delete, Details, Edit, List) supported by the non-CRUD scaffolder.
The "Blazor components using Entity Framework" scaffolder has the following options:
DbContext
or create a new one. The appropriate packages and startup configuration code should be applied to project for EF Core based on the user's selection.DbContext
: SQL Server, SQLite, PostgreSQL, Azure Cosmos DBLayoutComponentBase
). A note should be added saying "(Leave empty to use the default layout)".The "Blazor components using Entity Framework (CRUD)" scaffolder generates all of the template pages in one go. It has the same options as the "Blazor components using Entity Framework" scaffolder with the following exceptions:
Sample generated code
I've converted the scaffolded content for Razor Pages to Blazor components: https://github.com/danroth27/BlazorScaffolding. There are a number of limitations in Blazor that we need to address:
bool
:InputCheckbox
DateTime
,DateTimeOffset
,DateOnly
:InputDate
int
,long
,short
,float
,long
,decimal
:InputNumber
string
:InputText
enum
,enum[]
: InputSelectstring
:InputText
[Display]
attribute@mkArtakMSFT @javiercn @stevesandersonms @DamianEdwards