Click here to Skip to main content
Sign Up to vote bad
good
See more: ASP.NETMVC
Error:
Object reference not set to an instance of an object.
How to Solve.
Foreach line error display.
 
<table>
    <tr>
        <th>
            <%: Html.DisplayNameFor(model => model.Emp_Name) %>
        </th>
        <th>
            <%: Html.DisplayNameFor(model => model.Emp_Alies) %>
        </th>
        <th></th>
    </tr>
 
<% foreach (var item in Model) { %>
    <tr>
        <td>
            <%: Html.DisplayFor(modelItem => item.Emp_Name) %>
        </td>
        <td>
            <%: Html.DisplayFor(modelItem => item.Emp_Alies) %>
        </td>
        <td>
            <%: 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 }) %>
        </td>
    </tr>
<% } %>
 
</table>
Posted 10 Sep '12 - 21:26
Achal Oza1.3K

Comments
@amitgajjar - 11 Sep '12 - 3:57
check if you have Model null ?

1 solution

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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,356
1 OriginalGriff 6,571
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 11 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid