public ActionResult EditUser(long userId) { pageResourceManager.InsertTitlePart("后台管理-编辑用户资料"); ManageUsersEditModel model = null; string selectedValue = "0"; User user = userService.GetUser(userId) as User; if (user != null) { model = user.AsEditModel(); } ViewData["statusMessageData"] = TempData["statusMessage"]; List <SelectListItem> items = new List <SelectListItem>(); string[] reasons = { "亵渎", "广告", "发垃圾广告", "恶意攻击他人", "不雅的用户名", "恶意的链接或签名档", "其他" }; for (int i = 0; i < reasons.Count(); i++) { items.Add(new SelectListItem { Value = i.ToString(), Text = reasons.ElementAt(i) }); } if (reasons.Contains(user.BanReason)) { selectedValue = items.Where(n => n.Text == user.BanReason).FirstOrDefault().Value; } else { selectedValue = (reasons.Count() - 1).ToString(); } ViewData["reasons"] = new SelectList(items, "Value", "Text", selectedValue); return(View(model)); }