有一个将用于远程验证功能的类,但无法使其正常工作

[HttpPost]
public JsonResult doesUserNameExist(string Forename)
{
    IEnumerable<SelectListItem> user = new List<SelectListItem>();
    using (EIPInternalEntities ctx = new EIPInternalEntities())
    {
        user = new SelectList(ctx.Database
                                 .SqlQuery<string>("EXEC dbo.uspGetLkUpJobTitle")
                                 .ToList());
    }

    var userlist = user.ToList();

    //return Json(user == null);
    return Json(!userlist.Contains(Forename));
}


尝试了不同的方法,但当前(Forename))被标记为错误


  “参数1无法从'string'转换为
  'System.Web.Mvc.SelectListItem'


如果我尝试

var userlist = (SelectList)user;

//return Json(user == null);
return Json(!userlist.Contains(Forename));


然后是!userList。被警告说


  SelectList不包含包含的定义

最佳答案

尝试这个

return Json(!userlist.Any(x => x.Text == Forename));

09-10 06:36
查看更多