我在hibernate中創建了一個應用程序,我需要在創建視圖中創建一個下拉列表。在MVC中創建下拉列表nhibernate
下拉列表項是通過名爲getHobbytype()
的函數獲取的,我需要將所選值存儲到不同的數據庫中。在我創建視圖
ViewData["Hobby_type"] =
new SelectList(new Hobby_MasterService().GetHobbyType(),"Hobby_Types");
這:
我已經在我的控制器寫了這
@Html.DropDownListFor(Model =>
Model.Hobby_Types,(IEnumerable<SelectListItem>)ViewData["Hobby_type"])
通過這次我能夠創建下拉列表,但它給我這個我在下拉列表中查看錯誤:
沒有類型爲「IEnumerable」的ViewData項目具有「Hobby_Types」鍵。
這裏是我的GetHobbyType方法:
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;
}
請告訴我,我要去哪裏錯了。
ViewData [「Type」]我想你的意思是ViewData [「Hobby_Type」] – Iridio 2012-03-20 06:19:23
我更新了問題 – user1274646 2012-03-20 06:52:58
你也可以發佈'GetHobbyType'方法嗎? – Rippo 2012-03-20 07:46:39