0

在 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()改变什么?

4

1 回答 1

1

如果没有看到 的定义,我无法确定SecurityIdentiferMapping,但我猜那PricingSecurityID是类型int?。您正在尝试设置GetPricingSecurityID()此属性的返回值,但该方法的返回值是List<SelectItemList>

更改您的GetPricingSecurityID()方法以返回一个int?或您的属性以接受一个List<SelectItemList>.

于 2012-04-12T14:51:36.820 回答