1

I am trying to follow this tutorial from Microsoft:

Razor Pages with Entity Framework Core in ASP.NET Core - Tutorial 1 of 8: [https://learn.microsoft.com/en-us/aspnet/core/data/ef-rp/intro?view=aspnetcore-5.0&tabs=visual-studio]

I created the project correctly, but i can't run the project because when i replace the copied code from this step in tutorial "Set up the site style" in my project: Views/Home/Index.cshtml and I try to run is showing me:

The type or namespace name 'IndexModel' could not be found...

The problem seems to be here:

   @page
    @model IndexModel
    @{
        ViewData["Title"] = "Home page";
    }

Where is this model I can't find it, I just created the application, and the model does not exist? Or I pasted in the wrong file because in tutorial is saying: "Pages/Index.cshtml, replace the contents of the file with the following code:" I can't find neither "Pages" folder?

2 Answers 2

1

Apparently the screenshot on the page is misleading, because there is a selected MVC project while this tutorial needs to work in a "Web app" without MVC. I didn't see a point above where it says to select "Web app" without MVC, the mistake was mine but the picture is also misleading. I believe many people have slipped into this mistake.

The screenshot

Sign up to request clarification or add additional context in comments.

Comments

0

In your sample project, you should have:

Index.cshtml Index.cshtml.cs

The Index.cshtml.cs might appear nested under Index.cshtml (so expand that).

enter image description here

Check that the Index.cshtml.cs includes something like this:

namespace ContosoUniversity.Pages
{
    public class IndexModel : PageModel
    {
        private readonly ILogger<IndexModel> _logger;

        public IndexModel(ILogger<IndexModel> logger)
        {
            _logger = logger;
        }

        public void OnGet()
        {

        }
    }
}

You can see that this is where your IndexModel is declared.

Did you rename the page Index.cshtml? Did you rename or delete Index.cshtml.cs?

The .cs is called "code behind" because its the code that supports the .cshtml file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.