Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

HTML C# code not showing on webpage or page source

I Have the simplest web page, a line of text. When I dotnet build & dotnet run, then launch the webpage, nothing is displayed despite the code being built fine. Any ideas?

My HTML code

@page
@model WebApp.Pages.ViewActors
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Web App</title>
</head>
<body>
    <h1>@Model.Heading</h1>
</body>
</html>

My C# class

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

namespace WebApp.Pages
{
    public class ViewActors : PageModel
    {
        public String Heading { get; set; }
        public void onGet()
        {
            Heading = "James Bond Actors";
        }
    }
}

So Model.heading = "James Bond Actors"
But the page source only displays,

<html lang="en"><head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Web App</title>
</head>
<body>
    <h1></h1>

</body></html>

With nothing displayed between

<h1></h1>

Any help would be appreciated.

I’ve tried basic text and that displays but not the model.heading & viewed similar questions but no help. Thanks

>Solution :

onGet() should be OnGet() with a capital O.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading