Click here to Skip to main content
13,256,323 members (51,642 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Object reference not set to an instance of an object.
How to Solve.
Foreach line error display.

            <%: Html.DisplayNameFor(model => model.Emp_Name) %>
            <%: Html.DisplayNameFor(model => model.Emp_Alies) %>
<% foreach (var item in Model) { %>
            <%: Html.DisplayFor(modelItem => item.Emp_Name) %>
            <%: Html.DisplayFor(modelItem => item.Emp_Alies) %>
            <%: Html.ActionLink("Edit", "Edit", new { id=item.Emp_Id }) %> |
            <%: Html.ActionLink("Details", "Details", new { id=item.Emp_Id }) %> |
            <%: Html.ActionLink("Delete", "Delete", new { id=item.Emp_Id }) %>
<% } %>
Posted 10-Sep-12 22:26pm
Abhai Oza1.7K
@amitgajjar 11-Sep-12 3:57am
check if you have Model null ?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Object reference not set to an instance of an object

This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171114.1 | Last Updated 11 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100