Cannot access Controller properties in View using strongly typed view

224 Views Asked by At

I created a controller called Employeecontroller with the following function:

    Function Details() As ActionResult
        Dim myemployee As New Employee
        myemployee.Name = "John"
        Return View()
    End Function

After that I "Add a View" with the following settings:

View name: Details
Template: Empty
Model class
Employee(ProjeytName.Models)

According to this solution a strongley typed view is generated. My View Code looks like:

@ModelType MVC_AdminTry1.Models.Employee
@Code
    ViewData("Title") = "Employee Details"
End Code
<h2>@Model.Name</h2>

Now I get a Null Reference Error pointing to @Model.Name but I just cannot see, what is wrong. Could anyone help me here?

1

There are 1 best solutions below

0
sirrocco On BEST ANSWER

You need to send the model to the View:

Return View(myemployee)