2
votes

I am a Razor newbie, just can't run sample copied from : https://docs.microsoft.com/en-us/aspnet/core/razor-pages/?view=aspnetcore-2.2&tabs=visual-studio

My index.cshtml:

@page
@model IndexModel

<h2>Separate page model</h2>
<p>
    @Model.Message
</p>

My index.cshtml.cs

using Microsoft.AspNetCore.Mvc.RazorPages;
using System;

namespace aspnetcoreapp.Pages
{
    public class IndexModel : PageModel
    {
        public string Message { get; private set; } = "PageModel in C#";

        public void OnGet()
        {
            Message += $" Server time is { DateTime.Now }";
        }
    }
}

But when I browse this page I receive this error :

An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately. C:\temp\aspnetcoreapp\Pages\Index.cshtml

'IndexModel' does not contain a definition for 'Message' and no extension method 'Message' accepting a first argument of type 'IndexModel' could be found (are you missing a using directive or an assembly reference?) + @Model.Message

1

1 Answers

0
votes

The most common case of me getting this error is:

  1. Run the program without debugger
  2. Add property to the Razor page cs file and then analogous change to the cshtml file
  3. Refresh the page and get this error

What usually happens is that there is a compilation error, and the application has just failed to compile. May sound silly but make sure your application actually builds.