在 mvc3 应用程序中,我使用以下查询从数据库中填充下拉列表。在 Index.cshtml 上出现错误
public mydataEntities1 dbContext = new mydataEntities1();
public List<SelectListItem> GetPricingSecurityID()
{
var pricingSecurityID = (from m in dbContext.Reporting_DailyNAV_Pricing
select new SelectListItem
{
Text = m.PricingSecurityID.ToString(),
Value = m.PricingSecurityID.ToString()
});
return pricingSecurityID.ToList();
}
public List<SelectListItem> GetCUSIP()
{
var cusipID = (from m in dbContext.StateStreet_DailyPosition_Second
select new SelectListItem
{
Text = m.CUSIP.ToString(),
Value = m.CUSIP.ToString()
});
return cusipID.ToList();
}
Home.controller
public ActionResult Index()
{
SecurityIdentifierMapping objModel = new SecurityIdentifierMapping();
objModel.PricingSecurityID = objRepository.GetPricingSecurityID();
objModel.CUSIP = objRepository.GetCUSIP();
return View(objModel);
}
public partial class SecurityIdentifierMapping
{
public int Id { get; set; }
[Required(ErrorMessage = "Please select a PricingSecurityID")]
public Nullable<int> PricingSecurityID { get; set; }
[Required(ErrorMessage = "Please select a CUSIPID")]
public string CUSIP { get; set; }
public string Calculation { get; set; }
}
也试过AsEnumerable()
改变什么?