title: Creating a dropdown list in MVC nhibernate
body: <p>I'm creating an application in hibernate where i need to create a dropdown list in my Create View.</p>
  
  <p>The dropdownlist items are fetched through a function called <code>getHobbytype()</code> and from that I need to store the selected value into a different database.</p>
  
  <p>I have written this in my controller:</p>
  
  <pre><code>ViewData["Hobby_type"] = 
         new SelectList(new  Hobby_MasterService().GetHobbyType(),"Hobby_Types");
  </code></pre>
  
  <p>And this in my Create View:</p>
  
  <pre><code>@Html.DropDownListFor(Model =&gt; 
         Model.Hobby_Types,(IEnumerable&lt;SelectListItem&gt;)ViewData["Hobby_type"])
  </code></pre>
  
  <p>Through this I'm able to create the dropdown list but it is giving me this error inside my view on the dropdown:</p>
  
  <blockquote>
    <p>There is no ViewData item of type 'IEnumerable' that has the key 'Hobby_Types'.</p>
  </blockquote>
  
  <p>Here is my GetHobbyType Method:</p>
  
  <pre><code> public IList&lt;String&gt; GetHobbyType()
   {
     log.Debug("Started");
     ISession session = DataAccessLayerHelper.OpenReaderSession();
      IList&lt;String&gt; htype = null;
     ITransaction transaction = null;
    try
    {
      transaction = session.BeginTransaction();
      htype = session.CreateSQLQuery("SELECT Hobby_Types FROM Hobby_Type").List&lt;String&gt; ();
    session.Flush();
   transaction.Commit();
  }
      catch (Exception ex)
   {
     if (transaction != null &amp;&amp; transaction.IsActive)
     transaction.Rollback();
     log.Error(ex);
  
    }
    log.Debug("End");
    return htype;
    }
  </code></pre>
  
  <p>Please tell me where I'm going wrong.</p>