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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:04:40+00:00 2026-05-31T14:04:40+00:00

I’m creating an application in hibernate where i need to create a dropdown list

  • 0

I’m creating an application in hibernate where i need to create a dropdown list in my Create View.

The dropdownlist items are fetched through a function called getHobbytype() and from that I need to store the selected value into a different database.

I have written this in my controller:

ViewData["Hobby_type"] = 
       new SelectList(new  Hobby_MasterService().GetHobbyType(),"Hobby_Types");

And this in my Create View:

@Html.DropDownListFor(Model => 
       Model.Hobby_Types,(IEnumerable<SelectListItem>)ViewData["Hobby_type"])

Through this I’m able to create the dropdown list but it is giving me this error inside my view on the dropdown:

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

Here is my GetHobbyType Method:

 public IList<String> GetHobbyType()
 {
   log.Debug("Started");
   ISession session = DataAccessLayerHelper.OpenReaderSession();
    IList<String> htype = null;
   ITransaction transaction = null;
  try
  {
    transaction = session.BeginTransaction();
    htype = session.CreateSQLQuery("SELECT Hobby_Types FROM Hobby_Type").List<String> ();
  session.Flush();
 transaction.Commit();
}
    catch (Exception ex)
 {
   if (transaction != null && transaction.IsActive)
   transaction.Rollback();
   log.Error(ex);

  }
  log.Debug("End");
  return htype;
  }

Please tell me where I’m going wrong.

  • 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-31T14:04:41+00:00Added an answer on May 31, 2026 at 2:04 pm

    Is this a typo:-

    @Html.DropDownListFor(Model => 
           Model.Hobby_Types,(IEnumerable<SelectListItem>)ViewData["Type"])
    

    Should it not be

    @Html.DropDownListFor(Model => 
           Model.Hobby_Types,(IEnumerable<SelectListItem>)ViewData["Hobby_type"])
    

    Also your error says 'IEnumerable' that has the key 'Hobby_Types'.

    The key in ViewData is case sensitive (not to mention the error has an S on the end)

    I would also reccomend using a ViewModel rather than ViewData. See this Google search

    edit The GetHobbyType Method returns a List so try this:-

     ViewData["Hobby_type"] =    
       new SelectList(
        new Hobby_MasterService().GetHobbyType()
         .Select(x => new SelectListItem { Text = x, Value = x }).ToList()
       ,"Hobby_Types");
    

    I also suggest looking at using a viewmodel as it will save you lots of headaches!

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I want to construct a data frame in an Rcpp function, but when I
I have thousands of HTML files to process using Groovy/Java and I need to

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.