Amir Mirjalili
Amir Mirjalili

Reputation: 23

The "model" directive expects a type name

After installing .NET Core 3.1 none of Razor's commands work. As you can see in the picture, all Razor commands are red enter code here.

@model 
@{
    ViewData["Title"] = "LessonCreate";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

Upvotes: 1

Views: 6301

Answers (3)

trongtoannguyen
trongtoannguyen

Reputation: 45

for example

Lesson.cs


    namespace MyProject.Models;

    public class Lesson
    {
    ...
    }

Create.cshtml


    @model IEnumerable<MyProject.Models.Lesson>

Upvotes: 1

FadoBagi
FadoBagi

Reputation: 191

I had the same error and I had written this

@model List<MyModel>()

The solution was to simply remove the brackets

@model List<MyModel>

Upvotes: 3

Martin Staufcik
Martin Staufcik

Reputation: 9502

According to the documentation, the @model attribute expects a type name of the model. The syntax is:

@model TypeNameOfModel

You just need to provide the model type to the @model attribute, or remove the line, if the Razor view does not use a model.

Razor syntax reference for ASP.NET Core:

https://learn.microsoft.com/en-us/aspnet/core/mvc/views/razor?view=aspnetcore-3.1#directive-attributes

Upvotes: 2

Related Questions