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

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

public AlbumGetAllForArtist ( int id ) : IEnumerable
id int
Результат IEnumerable
        public IEnumerable<AlbumBase> AlbumGetAllForArtist(int id)
        {
            var a = ds.Artists
                .Include("Albums")
                .SingleOrDefault(art => art.ArtistId == id);

            if (a == null)
            {
                return null;
            }
            else
            {
                return Mapper.Map<IEnumerable<AlbumBase>>(a.Albums.OrderBy(alb => alb.Title));
            }
        }

Usage Example

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

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

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

            form.AlbumList = new SelectList(c, dataValueField: "AlbumId", dataTextField: "Title");

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

            // Attention - 08 - Notice several things in the list-of-albums view...
            // The dropdown list has an "onchange" attribute that calls a JavaScript method

            // Attention - 09 - Study the albumSelected() method in the JavaScript core.js source code file
        }