Click here to Skip to main content
15,884,099 members
Articles / Web Development / HTML

ASP.NET MVC - Part 1

Rate me:
Please Sign up or sign in to vote.
4.40/5 (34 votes)
7 Apr 2008CDDL13 min read 227.8K   9K   121  
A look at the ASP.NET MVC application in ASP.NET Extensions 3.5.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using Mvc.Models;
using System.Web.Routing;

namespace Mvc.Views.Music
{
    public partial class Artists :  ViewPage< List<Artist> >  //ViewPage 
    {
        protected override void OnLoad(EventArgs e)
        {
            // Create the menu
            AddMenu();

            ArtistList.DataSource = ViewData;
            // With the loosely coupled object collection, ViewData needs
            // to cast
            //ArtistList.DataSource = (List<Artist>)ViewData["Artists"];
            ArtistList.DataBind();
        }

        /// <summary>
        /// Create a simple alphabetic menu for navigation
        /// </summary>
        private void AddMenu()
        {
            // Build alphabetic menu
            for(char c = 'A'; c <= 'Z'; c++)
            {
                string link3 = Html.RouteLink(c.ToString(), new RouteValueDictionary(new { letter = c.ToString() }));
                //string link2 = Html.RouteLink(c.ToString(), "ArtistRoute", c);
                //string link2 = Html.RouteLink(c.ToString(), "ArtistRoute", new RouteValueDictionary(new { controller = "Music", letter = c.ToString() }));

                string link = Html.ActionLink(c.ToString(), "Artists", new RouteValueDictionary( new { controller = "Music", letter = c.ToString() }) );

                Alphabet.Controls.Add(new LiteralControl(link));
                // Add seperator
                if(c != 'Z')
                    Alphabet.Controls.Add(new LiteralControl(" | "));
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)



Comments and Discussions