score:0

Assuming you are talking about a directory, then you would have your letters action an event or set a variable that you can use in your linq.

var myData = entity.Where(o=>o.colName.StartsWith(letter)).OrderBy(o=>o.colName);

Maybe when they click on 'C' it does ?letter=C in querystring

You can then pick it out and use it as part of my above query, simplified slightly (Look up general usage of EF to create context etc)

score:0

This method will return a snippet of html markup with an A-Z roulette of links in it. If there are no jobs under the current letter then it will just show the letter without a link. I think you can modify this to your MVC project quite easily.

private string GetAlphaRouletteLinksHtmlMarkup()
{
    var JobList = new List<String>() {
        "AccessibleEmployment",
        "accessIndiana",
        "AccountingNet",
        "Alldiversity.com",
        "American Chemical Society",
        "America's Job Bank",
        "Art Careers",
        "Asian MBA",
        "Back Door Jobs",
        "Career Search",
        "Careerbliss",
        "Careerbuilder",
        "CareerJet",
        "CareerMagazine",
        "CareerMosaic",
        "CareerOverview",
        "Careers 2005",
        "City of Evansville jobs",
        "College Recruiter",
        "CollegeGrad.com",
        "ComputerJobs",
        "Conservation Job Board",
        "Cuyahoga County Public Library",
        "Dentist Jobs Help",
        "EMPLOYMENTCROSSING",
        "Evansville Courier & Press Classifieds",
        "Exam2Jobs",
        "Experience.com",
        "Federal Government Jobs",
        "Flipdog",
        "FPSelectJobs",
        "hotjobs",
        "Hound",
        "Idealist",
        "Indeed",
        "Indiana Health Careers",
        "Indiana Job Central",
        "Indiana Youth Institute",
        "IndianaCAREERConnect",
        "Inside Jobs",
        "Internships",
        "Jackson County Industrial Development Corporation",
        "Jamminjobs",
        "Job Application Center",
        "Job Search USA",
        "Job Seeker's Bookmarks",
        "Job-Applications",
        "JobCo",
        "Jobs in Indianapolis Web site",
        "JobScribble",
        "Journal of Young Investors",
        "Learn More Indiana",
        "Louisville, KY jobs",
        "Mediapost",
        "NBMBAA",
        "News-Line Communications",
        "On-Line Career Center",
        "Online Recruiters Directory",
        "PeaceCorps",
        "Quintessential Careers",
        "Riley Guide",
        "RiseSmart",
        "SallieMae True Careers",
        "ScienceJobs.com",
        "Simply Hired",
        "SmartBrief",
        "Snagajob.com",
        "State government job opportunities",
        "Student Employment Opportunities",
        "Teacher Jobs Help",
        "The Ladders Career Advice",
        "U. S. Department of State",
        "USAJOBS",
        "wetfeet",
        "WomensJobSearch",
        "Work In Sports",
        "WorkplaceDiversity"
    };

    var letters = from alpha in Enumerable.Range('A', 'Z' - 'A' + 1).Select(c => c.ToString())
                  let firstLetters = (from job in JobList
                                      orderby job
                                      group job by job[0].ToString().ToUpper() into firstLetters
                                      select firstLetters.Key)
                  select new
                  {
                      Letter = alpha,
                      IsLink = firstLetters.Contains(alpha)
                  };

    StringBuilder outputHtml = new StringBuilder();
    foreach (var item in letters)
    {
        if (item.IsLink)
        {
            // add html
            outputHtml.AppendFormat("<a href=\"#roulette{0}\">{1}</a> | ", item.Letter, item.Letter);
        }
        else
        {
            // no html
            outputHtml.Append(item.Letter);
            outputHtml.Append(" | ");
        }
    }

    return outputHtml.ToString().TrimEnd(" | ".ToCharArray());
}

All thats left for you to do is merge this code in and also keep your existing attempt which outputs the list of individual jobs.

Update - I improved by moving more of it into a single LINQ statement by pushing the first letters into a sub-select. Code posted is the updated version without the massive JobList declaration:

Update 2 - I replaced the string split with some more LINQ which generates the uppercase alphabet in this snippet and merged the updates together.


Related Articles