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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:04:56+00:00 2026-05-20T11:04:56+00:00

I am using MVC 2 and entity framework 4. On my create application page

  • 0

I am using MVC 2 and entity framework 4. On my create application page I have a drop down list which I populated with values from my AccountType enum. This is how I did it:

public ActionResult Create()
      {
         // Get the account types from the account types enum
         var accountTypes = from AccountType at
                            in Enum.GetValues(typeof(AccountType))
                            select new
                            {
                               AccountTypeID = (int)Enum.Parse(typeof(AccountType), at.ToString()),
                               AccountTypeName = GetEnumFriendlyName(at)
                            };
         ViewData["AccountTypes"] = new SelectList(accountTypes, "AccountTypeID", "AccountTypeName");

         return View();
      }

This is what my code looks like for this drop down list data:

<%= Html.DropDownList("AccountTypeID", (SelectList)ViewData["AccountTypes"], "-- Select --") %>

After the page loads I start to enter some values. I select a value from the drop down list. When all the required input is entered I click on submit. Below is just a piece of the code:

[HttpPost]
      public ActionResult Create(Application application)
      {
         if (ModelState.IsValid)
         {
            application.ApplicationState = (int)State.Applying;
         }

         return View();
      }

Then I get the following error, not sure what it means, but I did Google it, tried the samples, but I still get the message. Here is the error message:

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'AccountTypeID'.

I even changed the drop down list in the view to:

<%= Html.DropDownList("AccountTypeID", (IEnumerable<SelectListItem>)ViewData["AccountTypes"], "-- Select --") %>

I’m not sure what I am doing wrong? I would appreciate some input 🙂

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-05-20T11:04:56+00:00Added an answer on May 20, 2026 at 11:04 am

    In your POST action you need to fill the ViewData["AccountTypes"] the same way you did in your GET action because you are returning the same view and this view depends on it:

    [HttpPost]
    public ActionResult Create(Application application)
    {
        if (ModelState.IsValid)
        {
            application.ApplicationState = (int)State.Applying;
        }
    
        ViewData["AccountTypes"] = ... // same stuff as your GET action
        return View();
    }
    

    Obviously this answer comes with the usual disclaimer I always make when I see someone using ViewData instead of view models and strongly typed views: don’t use ViewData, use view models and strongly typed views.

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

Sidebar

Related Questions

Using ASP MVC and Entity Framework. In the view, you have a page declaration
I am using the asp.net mvc with the Entity Framework. I have a list
I have an ASP.NET MVC 3 application using an Entity Framework (4.3.1) Code First
I have an MVC-3 (RC1) application using Entity Framework 4. I wish to return
I am using MVC (C#) and the Entity Framework. I have a sql server
I am developing an ASP.Net MVC 3 Web application using Entity Framework 4.1 and
I am developing an ASP.Net MVC 3 Web application using Entity Framework 4.1, however,
I am writing an ASP.Net MVC 3 Web Application using Entity Framework 4.1. My
I am building an ASP.NET MVC web application using entity framework DbContext using the
I have a small MVC 3 app using Entity Framework Code First and use

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.