JQuery의 자동 완성을 통해 매개 변수를 전달하는 데 도움이 필요합니다. 나는 입력이있다 :jquery autocomplete passing parameters
<input type="text" class="form-control mb-2 mr-sm-2 mb-sm-0" name="searchName" id="searchName" placeholder="Nom et/ou prénom" />
형태로. 입력 때, JQuery와 자동 완성 기능은 Active Directory에서 검색을 시작하고 쇼 드롭 다운 목록을 초래할 : 지금은 양식 유효성 검사 후 그것을 할 단지 수에 대한
$(document).ready(function() {
$("#searchName").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Home/SearchUserWhileTyping",
type: "GET",
data: { name: $("#searchName").val() },
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (data) {
$("#searchName").html(''),
response($.map(data, function (item) {
return {
label: item
}
}));
}
});
},
minLength: 4
})
});
$(document).ready(function(){
$('#searchName').on('autocompletechange change', function() {
$('#searchValue').html('You selected: ' + this.value);
}).change()});
: 폼의 유효성을 검사 -> 내가로드 사용자가 발견 한 고유 ID -> 하나의 링크를 클릭하면 전달 된 고유 ID 덕분에 사용자 정보가 표시됩니다. 내가하고 싶은 일은 : 자동 완성 선택 항목 중 하나를 클릭하면 사용자의 정보가 직접 표시됩니다. 또 다른 기능은 AD를 검색 할 날 수 있으며 즉시하여 사용자를 찾을 도움이 될 것입니다 몇 가지 매개 변수를 (반환하기 때문에
[HttpGet]
public ActionResult SearchUserWhileTyping(string name)
{
ADManager adManager = new ADManager();
List<string> lastName = adManager.SearchUserByName(name);
List<string> splitList = new List<string>();
if (lastName != null)
{
if (lastName.Count <= 10)
{
int inc = 0;
foreach(string splitter in lastName)
{
if (inc % 2 == 1)
{
splitList.Add(splitter);
}
inc++;
}
return Json(splitList, JsonRequestBehavior.AllowGet);
}
}
return null;
}
내가 스플리터를 사용 : 당신이 입력하는 동안 여기
검색 코드입니다 그것의 유일한 ID, 저것은 나의 어려움이다). 나는 사용자의 내 목록이있을 때, 내가 그들의 링크를 클릭하면, 마지막으로public List<string> SearchUserByName(string name)
{
try
{
DirectoryEntry ldapConnection = createDirectoryEntry();
DirectorySearcher search = new DirectorySearcher(ldapConnection);
var sidInBytes=new byte[0];
//anr permet de chercher tout utilisateur contenant "name"
search.Filter = "(&(objectClass=user)(anr=" + name + "))";
//search.Filter = "(&(objectClass=User) (name=" + name + "*))";
search.PropertiesToLoad.Add("displayName");
search.PropertiesToLoad.Add("distinguishedName");
resultCollection = search.FindAll();
if (resultCollection.Count == 0)
{
return null;
}
else
{
foreach(SearchResult sResult in resultCollection)
{
if (sResult.Properties["distinguishedName"][0].Equals(null) ||
sResult.Properties["displayName"][0].Equals(null))
continue;
displayName.Add(sResult.Properties["distinguishedName"][0].ToString());
displayName.Add(sResult.Properties["displayName"][0].ToString());
}
}
ldapConnection.Close();
ldapConnection.Dispose();
search.Dispose();
return displayName;
}
catch (Exception e)
{
Console.WriteLine("Exception caught:\n\n" + e.ToString());
}
return null;
}
나는이 기능을 사용하여 사용자에 대한 정보를로드 : 이것은 다음과 같은 함수를 호출
public List<KeyValuePair<string,string>> GetUserInfoBySAMAN(string sAMAccountName)
{
try
{
DirectoryEntry ldapConnection = createDirectoryEntry();
DirectorySearcher search = new DirectorySearcher(ldapConnection);
search.Filter = "(sAMAccountName=" + sAMAccountName + ")";
search.PropertiesToLoad.Add("objectSID");
search.PropertiesToLoad.Add("displayName");
search.PropertiesToLoad.Add("memberOf");
search.PropertiesToLoad.Add("description");
search.PropertiesToLoad.Add("accountExpires");
search.PropertiesToLoad.Add("sAMAccountName");
result = search.FindOne();
///Conversion du SID en chaine de caractères
var sidInBytes = (byte[])result.Properties["objectSID"][0];
var sid = new SecurityIdentifier(sidInBytes, 0);
String time;
if (result.Properties["accountExpires"][0].ToString().Equals("0")|| result.Properties["accountExpires"][0].ToString().Equals("9223372036854775807"))
{
time = "Jamais";
}
else
{
///Conversion de la date en entier puis en date
DateTime dt = new DateTime(1601, 01, 02).AddTicks((Int64)result.Properties["accountExpires"][0]);
time = dt.ToString();
}
string desc="";
if (result.Properties.Contains("description"))
{
desc = result.Properties["description"][0].ToString();
}
else
{
desc = "Pas de description disponible";
}
userInfo = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("displayName",result.Properties["displayName"][0].ToString()),
new KeyValuePair<string, string>("memberOf", result.Properties["memberOf"][0].ToString()),
new KeyValuePair<string, string>("accountExpires",time),
new KeyValuePair<string, string>("description",desc),
new KeyValuePair<string, string>("sid",sid.ToString()),
new KeyValuePair<string, string>("sAMAccountName",result.Properties["sAMAccountName"][0].ToString())
/*lastName.Add(result.Properties["displayName"][0].ToString());
lastName.Add(result.Properties["memberOf"][0].ToString());
lastName.Add(sid.ToString());
lastName.Add(result.Properties["accountExpires"][0].ToString());
lastName.Add(result.Properties["description"][0].ToString());*/
};
return userInfo;
}
catch(Exception e)
{
Console.WriteLine("Exception caught:\n\n" + e.ToString());
}
return null;
}
마지막으로 그를 함수는 distinguishedName으로 sAMAccountName을 변경하면이 속성을 사용할 수 없으므로 작동하지 않습니다. 나는 distinguishedName을 사용하고 즉시 내 객체를 갖고 싶습니다.
그래서 내가 입력하는 동안 검색하는 것이고 제안 된 선택 사항 중 하나를 선택하면 즉시 양식 유효성 검사를 통해 사용자 정보 페이지로 이동합니다. 당신의 도움에 대한
덕분에, 내가 선택한 항목의 값을 얻을 수있는 제 2의 스크립트를 추가 편집 충분히
분명 희망하지만 내가 만약 컨트롤러
선택한 플러그인 사용, 변경시, 값 선택시 표시 할 항목 표시? – Munzer
내 질문을 편집했습니다. 내가 제안한 스크립트를 추가하여 값을 선택하도록했습니다. 문제는 SearchUserWhileTyping 메서드에 있는데 이름 목록 만 검색하고 distinguishedName 특성을 추가하면 내 목록에 표시됩니다 (원하지 않음). –