Skip to content

[Feature] Ability to control abstract and sealed modifier of generated Razor Pages classes #12875

@demigor

Description

@demigor

Hi,

Imagine you have lot of similar pages, that could share the same functionality.
You could define one Razor Page and @inherit others from it, effectively sharing same helpers, functions and variables.
You could have virtual methods defined, that could be overriden in derived classes thus tuning the inherited behaviour.

Right now, you could manually define an abstract Page in code, put all you shared methods there and use @inherits in cshtml pages.

What is missing is ability to share Razor markup (@Helper methods, rendering functions), because you cannot use Razor Syntax in plain C# file.

Would it be possible to add a project level setting that controls sealing of generated Razor Page classes. Or provide additional @abstract control pragma to generate abstract, unsealed class without own render method, but with all other stuff declared.

There will be no noticable performance penalty for unsealed classes neither in Jit, not in AOT.
However the usability of Razor Pages will rise on another level.

Thank you

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions