Results 1 to 2 of 2

Thread: Object reference not set to an instance of an object.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Unhappy Object reference not set to an instance of an object.

    The following is my View's code
    Code:
     @foreach (var item in Model.UserRoles)
            {
                for (i = 0; i < Model.UserRoles.Count ; i++)
                {
                @Html.HiddenFor(users => users.UserRoles[i].UserRoleID)       
                @Html.HiddenFor(users => users.UserRoles[i].UserID)     
                @Html.HiddenFor(users => users.UserRoles[i].RoleID)     
                @Html.HiddenFor(users => users.UserRoles[i].CreatedBy)     
                @Html.HiddenFor(users => users.UserRoles[i].CreatedDate)   
                @Html.HiddenFor(users => users.UserRoles[i].UpdatedBy)   
                @Html.HiddenFor(users => users.UserRoles[i].UpdatedDate)   
                @Html.HiddenFor(users => users.UserRoles[i].Status)   
                @Html.HiddenFor(users => users.UserRoles[i].OrganizationID)   
               }
           }
    The first line of foreach is showing "Object reference not set to an instance of an object." error...

    Thanks in advance

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Object reference not set to an instance of an object.

    It sounds like the UserRoles property of your model is null. Check your controller action code where you expect it to be populated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width