Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8528705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:51:45+00:00 2026-06-11T08:51:45+00:00

By SelectListItem I get System.NullReferenceException: Object reference not set to an instance of an

  • 0

By SelectListItem I get “System.NullReferenceException: Object reference not set to an instance of an object.” error. What do I wrong?

This is my xml:

<?xml version="1.0" encoding="utf-8"?>
<Artiesten>
  <Item ID_Artiest="509998" Artiest="-" Product="-" Land="" Plaats="" Website="" Genre="Onbekend" />
  <Item ID_Artiest="970119" Artiest="(hed)p.e." Product="-" Land="" Plaats="" Website="" Genre="Onbekend" />
  <Item ID_Artiest="970080" Artiest="(urusei) yatsura" Product="-" Land="" Plaats="" Website="" Genre="Noise" />
  <Item ID_Artiest="1010302" Artiest="...and you will know us by the trail of dead" Product="-" Land="Verenigde Staten" Plaats="Austin (TX)" Website="" Genre="Noise" />
...
</Artiesten>

This is my Model

public class ArtiestInfoModel
    {
        [DisplayName("Selecteer artiest: ")]
        public int ID_Artiest { get; set; }
        public string SelectedArtiest { get; set; }
        public IEnumerable<SelectListItem> ArtiestenLijst { get; set; }
    }

The Controller:

 public ActionResult Index(int? AID_Artiest=810000)
        {
            var document = XDocument.Load(Server.MapPath("~/App_Data/Artiesten.xml"));
            var query = new ArtiestInfoModel
            {
                ArtiestenLijst =
                    (from artiest in document.Descendants("Artiesten").Elements("Item")
                    select new SelectListItem
                    {
                        Value = artiest.Attribute("ID_artiest").Value,
                        Text = artiest.Attribute("Artiest").Value,
                        Selected = false //  artiest.Attribute("ID_artiest").Value == AID_Artiest.ToString()
                    }).ToList()
            };

            ViewBag.ID_Artiest = AID_Artiest.Value;
            ViewBag.ArtiestenLijst = query.ArtiestenLijst;

            return View();
        }

The Controller is called by the next DropDownList:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">    
    <% using (Html.BeginForm("Index", "Hitdossier", FormMethod.Post, new { id = "frmArtiest" })) %>
    <% { %>
        <table><tr><th width="1000" align="left">Selecteer artiest:</th></tr>
            <tr>
                <td><%= Html.DropDownList("ID_Artiest",
                    new SelectList(ViewBag.ArtiestenLijst, "Value", "Text"),
                    "-- Selecteer artiest --",
                    new
                    {
                        @onchange = "document.getElementById('frmArtiest').submit();"
                    })%>
                </td>
            </tr>
        </table>
        <br />
        <br />
        <div id="divPartialView">
            <%= Html.Action("Detail_Hitdossier", new { AID_Artiest = ViewBag.ID_Artiest })%> <br />
        </div>
    <%} %> 
</asp:Content>

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:51:46+00:00Added an answer on June 11, 2026 at 8:51 am

    In your controller you are reading the node ID_artiest as a lowercase while the xml shows camelcase.

    Change

    Value = artiest.Attribute("ID_artiest").Value,
    

    To

    Value = artiest.Attribute("ID_Artiest").Value,
    

    If artiest.Attribute("ID_artiest") result in a NULL value, then reading a property Value will throw the null-reference-exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the following exception: Exception Details: System.NullReferenceException: Object reference not set to
My model looks like this public IEnumerable<SelectListItem> ProductTypes { get; set; } public ProductContent()
Previously, I was using this in my model public List<SelectListItem> StatusList { get; set;
Possible Duplicate: MVC3 Razor (Drop Down List) I've been getting Object reference not set
On an empty table in the database I get the this error on the
In my viewModel I have public string Addressline1 { get; set; } public List<SelectListItem>
//Model public class SelectModel { public string CategoryId { get; set; } public List<SelectListItem>
my viewmodel public class CaseCreateInput { [PartialView(My)] public object AreaId { get; set; }
I have below variables public IEnumerable<SelectListItem> SelectedGroups { get; set; } Dictionary<string,string> grpsList; Below
I am attempting to get a Select List from an XML string... <?xml version=1.0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.