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

  • Home
  • SEARCH
  • 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 9135475
In Process

The Archive Base Latest Questions

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

I am probably doing something silly but cannot find out what. I am trying

  • 0

I am probably doing something silly but cannot find out what. I am trying to modify simple membership functionality in ASP.NET MVC 4. I have slightly modified a RegisterModel coming with the template, and added a list of categories to it like so:

public class RegisterModel
{
    ...

    public List<SelectListItem> Categories { get; set; }
}

Then in the account controller I’m trying to add an item to this list but get “Object reference not set to an instance of an object.” error:

[AllowAnonymous]
public ActionResult Register()
{
    RegisterModel rm = new RegisterModel();

    //SelectListItem guestCategory = new SelectListItem();
    //guestCategory.Value = null;
    //guestCategory.Text = "Guest";

    rm.Categories.Add(new SelectListItem { Value = null, Text = "Guest" });
...

Any ideas why?

  • 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-17T08:49:46+00:00Added an answer on June 17, 2026 at 8:49 am

    you just need to do this before adding items to list , because when you add items its not get instantiated that why its giving error

    rm.Categories = new List<SelectListItem>();
    

    that means in this method do like this

    [AllowAnonymous]
    public ActionResult Register()
    {
        RegisterModel rm = new RegisterModel();
    
        rm.Categories = new List<SelectListItem>();//added line 
    
        rm.Categories.Add(new SelectListItem { Value = null, Text = "Guest" });
    ...
    

    or

    you can do same thing in constructor of RegisterModel .

    public class RegisterModel
    {
      public RegisterModel
      {
        Categories = new List<SelectListItem>();//added line 
      }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm probably doing something silly, but here it goes. I'm trying to get the
I'm probably doing something silly here but I've been trying to install the mongodb
I am doing something that is probably silly, but it would be nice if
I am still a beginner but trying to learn so probably doing something extremely
I'm probably doing something very silly but I can't extract the parameter values from
Im probably doing something dumb here but I can't figure out why both of
I'm probably doing something stupid but I can't figure out what it is. The
Another noob regex problem/question. I'm probably doing something silly so I thought I'd exploit
I'm probably doing something realy stupid but I cant get this to work: var
I know this probably really simple but Im not sure what im doing wrong...

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.