AjaxItemSelect.Controllers.Manager.TrackGetAllForAlbum C# (CSharp) Метод

TrackGetAllForAlbum() публичный Метод

public TrackGetAllForAlbum ( int id ) : IEnumerable
id int
Результат IEnumerable
        public IEnumerable<TrackBase> TrackGetAllForAlbum(int id)
        {
            var a = ds.Albums
                .Include("Tracks")
                .SingleOrDefault(alb => alb.AlbumId == id);

            if (a == null)
            {
                return null;
            }
            else
            {
                return Mapper.Map<IEnumerable<TrackBase>>(a.Tracks.OrderBy(t => t.Name));
            }
        }

Usage Example

Пример #1
0
        // GET: Tracks/Tracks/5
        // Attention - 10 - This get-tracks-for-album method is called from JavaScript+Ajax
        public ActionResult Tracks(int?id)
        {
            // Fetch the collection
            var c = m.TrackGetAllForAlbum(id.GetValueOrDefault());

            // If null, create an empty collection
            if (c == null)
            {
                c = new List <TrackBase>();
            }

            // Create a form
            var form = new TrackForm();

            form.TrackList = new SelectList(c, dataValueField: "TrackId", dataTextField: "Name");

            return(PartialView("_TrackList", form));

            // Attention - 11 - Look at the list-of-tracks view
        }