此方法将返回一个带有 AZ 轮盘链接的 html 标记片段。如果当前字母下没有工作,那么它只会显示没有链接的字母。我认为您可以很容易地将其修改为您的 MVC 项目。
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());
}
剩下要做的就是合并此代码,并保留您现有的输出单个作业列表的尝试。
更新 - 我通过将第一个字母推入子选择将更多内容移动到单个 LINQ 语句中进行了改进。JobList
发布的代码是没有大量声明的更新版本:
更新 2 - 我用更多的 LINQ 替换了字符串拆分,该 LINQ 在此代码段中生成大写字母并将更新合并在一起。