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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:53:03+00:00 2026-06-13T07:53:03+00:00

Reading from here: ASP.NET MVC Action SelectCategory has been created inside controller – public

  • 0

Reading from here: ASP.NET MVC

Action SelectCategory has been created inside controller –

 public ActionResult SelectCategory() {

     List<SelectListItem> items = new List<SelectListItem>();    
     items.Add(new SelectListItem { Text = "Action", Value = "0"});    
     items.Add(new SelectListItem { Text = "Drama", Value = "1" });    
     items.Add(new SelectListItem { Text = "Comedy", Value = "2", Selected = true });    

     ViewBag.MovieType = items;

     return View();    
 }

I am not able to understand binding of Data in following line.

@Html.DropDownList("MovieType")

While binding data in similar way,

@Html.DropDownList("IdList");

I obtain following error-

There is no ViewData item of type ‘IEnumerable’ that
has the key ‘IdList’.

Controller Action:

public ActionResult SelectId()
    {
        List<SelectListItem> items = new List<SelectListItem>();
        items.Add(new SelectListItem { Text = "MyId1", Value = "MyId1", Selected=true });
        items.Add(new SelectListItem { Text = "MyId2", Value = "MyId2" });

        ViewBag.IdList = items;
        return View();
    }

What am I missing ? Thank you for your help !

  • 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-13T07:53:04+00:00Added an answer on June 13, 2026 at 7:53 am

    You have set ViewBag.MovieType => when you use @Html.DropDownList("MovieType") the dropdown will use this value. When you write @Html.DropDownList("IdList"), the helper doesn’t find a corresponding IdList property in ViewBag and throws an error because it doesn’t know from where to bind the data.

    Alternatively if you want to change the name of the dropdown you could use the following:

    @Html.DropDownList("SelectedMovieType", (IEnumerable<SelectListItem>)ViewBag.MovieType)
    

    and your POST action will have a SelectedMovieType parameter to retrieve the selected value.

    But I would avoid ViewBag. Defining a view model is better:

    public class MyViewModel
    {
        public string SelectedMovieType { get; set; }
        public IEnumerable<SelectListItem> MovieTypes { get; set; }
    }
    

    and then have your controller action populate this view model and pass it to the view:

    public ActionResult SelectId()
    {
        List<SelectListItem> items = new List<SelectListItem>();
        items.Add(new SelectListItem { Text = "MyId1", Value = "MyId1", Selected=true });
        items.Add(new SelectListItem { Text = "MyId2", Value = "MyId2" });
    
        var model = new MyViewModel
        {
            MovieTypes = items    
        };
    
        return View(model);
    }
    

    and in your strongly typed view:

    @model MyViewModel
    @Html.DropDownListFor(x => x.SelectedMovieType, Model.MovieTypes)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been reading Scott Gu's post on code first design with ASP.Net MVC 2.0
I am a newbie in ASP.NET MVC and learning from zero now by reading
I've been reading Pro ASP.NET MVC Framework, Steven Sanderson, and in chapter 11 it
I am reading a post about mobile web development and ASP.NET MVC here: http://www.hanselman.com/blog/ABetterASPNETMVCMobileDeviceCapabilitiesViewEngine.aspx
I have an asp.net-mvc website and i am reading in Json string from a
I've been reading some async articles here: http://www.asp.net/web-forms/tutorials/aspnet-45/using-asynchronous-methods-in-aspnet-45 and the author says : When
Here's an excerpt from a book I'm reading about application design with MVC: Ideally,
Recently I've read, and implemented 80% of examples from Pro ASP.NET MVC Framework ,
I'm trying to use async from the asp.net mvc futures, using my own async
I'm looking at the new version of ASP.NET MVC (see here for more details

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.