Skip to content

Define a Blazor Page using .razor.cs file only; no .razor file #31162

@JohnGoldInc

Description

@JohnGoldInc

Is your feature request related to a problem? Please describe.

I was hoping the "Test.razor.cs" file below (with no corresponding "Test.razor" file hence no "partial" ) would actually work as a Page for example. But I get the "Sorry, there's nothing at this address." error when going to ".../Test"

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using NorthWind.UI.Shared;

namespace NorthWind.UI.Pages
{
    public class Test : ComponentBase
    {

        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            builder.OpenComponent(0, typeof(SurveyPrompt));
            builder.AddAttribute(1, "Title", $"Some Test");
            builder.CloseComponent();

            base.BuildRenderTree(builder);
        }
    }
}

Describe the solution you'd like

A way to add code only Blazor pages on Startup to Page routes that evaluate, either automatically or via an extension method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions