I'm having a problem with the List<SelectListItem>
. Whenever the code hits the foreach
it says:
object reference not set to an instance of an object.
Am I missing something or can anyone explain why it is failing there?
public ActionResult HammerpointVideos(string category, string type)
{
var stuff = Request.QueryString["category"];
var ItemId = (from p in entities.EstimateItems
where p.ItemName == category
select p.EstimateItemId).FirstOrDefault();
var Videos = (from e in entities.EstimateVideos
where e.EstimateItemId == ItemId
select new Models.HammerpointVideoModel
{
VideoName = e.VideoName,
VideoLink = e.VideoLink
}).ToList();
var model= new Models.HammerpointVideoListModel();
List<SelectListItem> list = model.VideoList;
foreach (var video in Videos)
{
list.Add(new SelectListItem()
{
Selected=false,
Value = video.VideoLink,
Text = video.VideoName
});
}
}
VideoList
? – DGibbs Jun 18 '13 at 12:43where e.EstimateItemId == ItemId
...but ItemId isn't an int type, it's an unspecifiedvar
. I have no idea if that is the issue, but if it is, then the reason your code doesn't work is because it can't distinguish the VALUE ofItemId
, and so the second linq block returns no results. I may be way off however. Other people? Is this a possibility? I haven't touched LINQ in a year, so I'm a bit rusty there. – Russell Uhl Jun 18 '13 at 12:46