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 7845001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:04:41+00:00 2026-06-02T17:04:41+00:00

This is my combined model: public class AddArticleModel { public TBL_ARTICLES Article { get;

  • 0

This is my combined model:

public class AddArticleModel
{
    public TBL_ARTICLES Article { get; set; }
    public IEnumerable<TBL_CATEGORIES> Categories { get; set; }
}

And controller that is use model.

public ActionResult AddArticle()
{
    AddArticleModel AddArticleModel = new AddArticleModel();
    AddArticleModel.Categories = entity.TBL_CATEGORIES.Select(a => a);

    return View(AddArticleModel);
}

And View :

@model DunyaYazilim.Models.AddArticleModel
@{
    ViewBag.Title = "AddArticle";
}
@using (Html.BeginForm((string)ViewBag.FormAction, "Home"))
{
    <fieldset>
        <legend>Add Article Form</legend>
        <ol>
            <li>
                @Html.DropDownListFor(m => m.Categories, Model.Categories.Select(c => new SelectListItem { Text = c.Name, Value = c.CategoryID.ToString() }), "-----Select Category----")
            </li>
        </ol>
        <input type="submit" value="Send" />
    </fieldset>
}

And Posted Method in controller:

[HttpPost]
public ActionResult AddArticle(AddArticleModel AddArticleModel)
{
   //Insert operations:
   return View(AddArticleModel);
}

My question: When I posted the form, Occur an error : Object reference not set to an instance of an object. In line:13

Line 12:             <li>
Line 13:                 @Html.DropDownListFor(m => m.Categories, Model.Categories.Select(c => new SelectListItem { Text = c.Name, Value = c.CategoryID.ToString() }), "-----Select Category----")
Line 14:             </li>
Line 15:             <li>

What the reason for this?

Note: There are a lot of examle in this site. I tried many of them, but I could not find reason of error.

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-02T17:04:43+00:00Added an answer on June 2, 2026 at 5:04 pm

    I’m not sure if you posted the full code for your POST operation, but if you did then it’s wrong.

    When you post data to the server, you are not posting the values of your SelectList. You are only posting the selected value. If you are just displaying the view back to the user, then the SelectList will be null. You need to repopulate it in the Post:

    [HttpPost]
    public ActionResult AddArticle(AddArticleModel AddArticleModel)
    {
        AddArticleModel.Categories = entity.TBL_CATEGORIES.Select(a => a);
    
        return View(AddArticleModel);
    }
    

    If you only want to return the selected category (seems odd) this will do it:

    [HttpPost]
    public ActionResult AddArticle(AddArticleModel AddArticleModel)
    {
        AddArticleModel.Categories = entity.TBL_CATEGORIES.Where(a => a.CategoryId == AddArticleModel.CategoryId);
    
        return View(AddArticleModel);
    }
    

    This assumes that the property on your view model is CategoryId and the property on your TBL_CATEGORIES entity is also CategoryId.

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

Sidebar

Related Questions

I got this error running a query that goes against 2 tables with combined
I have the following code in my controller: // GET: /Review/Create public ActionResult Create()
This is my upload Action : [HttpPost] public ActionResult addcar(Models.vehicule model) { ViewBag.cat =
What I want to do is something like this: I have enums with combined
Background ArticleService is a class that provides methods for front-end layers to facilitate business
So, say I have a simple enum and a class that uses it: enum
I'm trying to model a certain process and I'm thinking that the State Pattern
I have a query that produces the following output in a nested set structure:
I am trying to create a model instance that includes a list of model
I have a generic class which represents a fragment of text. That fragment of

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.