Выберите 2, не заполненный ajax и нумерацией страниц - PullRequest
0 голосов
/ 14 октября 2019

Я хочу заполнить элемент управления select 2 учетной записью пользователей активного каталога для вставки их в базу данных, но даже если я вижу, что в ответ на запрос json с помощью F12, select 2 не заполняется

на используемый select2 ссылаетсяв общем / макетном представлении

есть по контроллеру метод действия

public JsonResult GetUsersFiltredPaged(string match, int page = 1, int pageSize = 5)
    {
        PrincipalContext contextPrincipal = new PrincipalContext(ContextType.Domain);
        var userPrincipal = new UserPrincipal(contextPrincipal);
        PrincipalSearcher searchPrincipal = new PrincipalSearcher(userPrincipal);
        var totalCount = searchPrincipal.FindAll().Count();
        List<UserPrincipal> usersAD = new List<UserPrincipal>();

        foreach (UserPrincipal users in searchPrincipal.FindAll())
        {
            if (users.EmployeeId != null)//prendre les comptes qui ayant un matricule paie
            {
                UserPrincipal userAd = users;
                userAd.DisplayName = users.DisplayName + '(' + users.EmailAddress + ')';
                userAd.EmployeeId = users.EmployeeId;
                usersAD.Add(userAd);
            }
        }
        IEnumerable<ModelDto> model = (from u in usersAD.AsQueryable().OrderBy(i=>i.DisplayName).Skip(page*(pageSize-1))
                                            .Take(pageSize)
                                select new ModelDto{id= u.EmployeeId, text=u.DisplayName});
        if (!string.IsNullOrWhiteSpace(match))
        {
            model = model.Where(i => i.text.Contains(match));
        }


            ResultList<ModelDto> results = new ResultList<ModelDto> { items = model.ToList(), totalCount = usersAD.Count };
            return Json(results, JsonRequestBehavior.AllowGet);



    }

бритва моего выпадающего списка

     @using (Html.BeginForm("RegisterModify", "Account", FormMethod.Post, new { @class = "form-horizontal"}))
     {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)

       <div class="well blanc" >

          <div class="form-group">
            @Html.LabelFor(model => model.SelectedMatric, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
            @Html.DropDownListFor(model => model.SelectedMatric, Model.DisplayedNames, "--Selectionnez--", new { @class = "form-control" })
            @*@Html.HiddenFor(model => model.SelectedMatric, new { id="SelectedMatric"})*@
            @Html.ValidationMessageFor(model => model.SelectedMatric, "", new { @class = "text-danger" })
        </div>
    </div>

  @*the rest of view *@
  <p>
        <input type="submit" value="Créer" class="btn btn-primary" />
  </p>

код сценария Java

  $('#SelectedMatric').select2({
            placeholder: "--Selectionnez--",
            width: '100%',
            minimumInputLength: 0,
            allowClear: true,
            ajax: {
                url: '@Url.Action("GetUsersFiltredPaged")',
                dataType: 'json',
                type: 'Get',

                data: function (term, page) {
                    return { match: term, page: page, pageSize: 5 };
                },
                results: function (result, page) {
                    var more = (page * 5) < result.totalCount;
                    return { results: result.items, page: page, more: more };
                }
            }
        });
...