inside mvc3 application i’m populating dropdownlist from database using following query.
getting error on 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; }
}
tried AsEnumerable() also what to change?
I can’t be certain without seeing the definition for
SecurityIdentiferMapping, but I’m going to guess thatPricingSecurityIDis of typeint?. You are trying to set the return value ofGetPricingSecurityID()to this property, but the return value of that method isList<SelectItemList>Change your
GetPricingSecurityID()method to return anint?or your property to accept aList<SelectItemList>.