var editionList =
from edition in software.Editions
select new
{
ID = edition.ID,
Name = edition.Name
};
How can I ensure that the result starts with an "empty" row
ID = -1, Name = "<select>"
So that I can use this in a HTML drop down?
There's got to be a more simple way that what I am currently doing....
var blankSoftware =
from software in new string[] { "" }
select new { ID = -1, Name = "" };
var softwareList =
from product in softwareRepository.GetAll()
select new
{
ID = product.ID,
Name = product.Name
};
ViewData["SoftwareList"] = blankSoftware.Union(softwareList);
Thanks
Pete
Jon Skeet [C# MVP] - 07 Mar 2008 18:33 GMT
> var editionList =
> from edition in software.Editions
[quoted text clipped - 8 lines]
>
> So that I can use this in a HTML drop down?
After the above, use:
editionList = Enumerable.Repeat (new { ID=-1, Name="<select>" }, 1)
.Concat (editionList);
If you find yourself frequently doing this kind of thing, you might
like to write extension methods of Prepend and Append, which
prepend/append a single element of type T to an IEnumerable<T> - in
exactly the same way as the above.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Peter Morris - 07 Mar 2008 19:15 GMT