I have the following MVC
Public Class Employee Public Property EmployeeID As Integer End Class
Namespace Controllers Public Class EmployeeController Inherits Controller Function Details() As ActionResult Dim employee As Employee employee = New Employee employee.EmployeeID = 101 Return View() End Function End Class End Namespace
@ModelType MVCDemo.Employee @Code ViewData("Title") = "Employee Details" End Code <h2>Employee Details</h2> <table style="font-family:Arial"> <tr> <td> @Model.EmployeeID </td> </tr> </table>
My Problem: Running the code I get the following error:
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
For the line:
Line 11: @Model.EmployeeID
I just do not know why there is no object reference. I get intellisense for the Model in the razor code. The initialiation and assigning the value to the property is ok. Mybe I am just blind, could anyone help me why this is not working?