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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:22:04+00:00 2026-05-28T16:22:04+00:00

I looked at similar posts but nothing working for my case. I have a

  • 0

I looked at similar posts but nothing working for my case.
I have a form which loads fine and I see the categories dropdown with all categories in it.
The problem is when I try to post the form.

I get this error:

The ViewData item that has the key ‘Category’ is of type ‘System.String’ but must be of type ‘IEnumerable’.

@Html.DropDownList(“Category”, Model.Categories) <– red color

Here is my view:

@using (Html.BeginForm("Save", "Album", FormMethod.Post, new { id = "frmNewAlbum" }))
{                
   @Html.DropDownList("Category", Model.Categories)
}

Here is my model:

public class AlbumModel
{        
        public string Title { get; set; }

        public string Category { get; set; }

        public List<SelectListItem> Categories { get; set; } <-- holds categories
}

This is the controller actions to view the page:

[HttpGet]
public ActionResult Save()
        {
            var model = new AlbumModel();
            var categories = new List<SelectListItem>() { new SelectListItem() { Text = "-- pick --" } };
            categories.AddRange(svc.GetAll().Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }));
            model.Categories = categories;
            return View(model);
        }

Action that receives the post:

[HttpPost]
    public ActionResult Save(AlbumModel model)
    {            
                var album = new AlbumDoc()
                {                        
                    Category = model.Category,
                    Title = model.Title,
                };

                svc.SaveAlbum(album);

        return View(model);
    }
  • 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-28T16:22:05+00:00Added an answer on May 28, 2026 at 4:22 pm

    In your POST action you seem to be redisplaying the same view but you are not populating the Categories property on your view model which will contain the dropdown list values. And by the way I would recommend you using strongly typed helper. So:

    public class AlbumController: Controller
    {
        [HttpGet]
        public ActionResult Save()
        {
            var model = new AlbumModel();
            model.Categories = GetCategories();
            return View(model);
        }
    
        [HttpPost]
        public ActionResult Save(AlbumModel model)
        {            
            var album = new AlbumDoc()
            {                        
                Category = model.Category,
                Title = model.Title,
            };
            svc.SaveAlbum(album);
            model.Categories = GetCategories();
            return View(model);
        }
    
        private IList<SelectListItem> GetCategories()
        {
            return svc
                .GetAll()
                .ToList()
                .Select(x => new SelectListItem
                { 
                    Text = x.Name, 
                    Value = x.Name 
                });
        }
    }
    

    and in your view:

    @model AlbumModel
    ...
    @using (Html.BeginForm("Save", "Album", FormMethod.Post, new { id = "frmNewAlbum" }))
    {                
       @Html.DropDownListFor(
           x => x.Category, 
           Model.Categories,
           -- pick --
       )
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have looked around and saw a few posts on similar things but
I have looked at some of the other posts made on similar topics but
I've looked at some of the posts that have similar issues, but I can't
I've looked at similar problems but I simply can not see what is going
I have looked for similar questions, but could find none other than the difference
I looked at other similar posts, but none that helped. Here is my code:
(I've looked at many other similar posts on SO and have unfortunately not been
Sorry if this has been answered before; I've looked at similar posts here but
I've looked at some similar posts regarding interaction delay after page load, but I
Let me start by saying I have looked at many similar questions asked, but

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.