weixin_33712881 2014-06-18 17:14 采纳率: 0%
浏览 20

更新每个笔触的过滤器

I'm using C# in MVC 5. Trying to update my search results upon every key stroke. I've wrote what I think would be logical. In my View I wrote some Ajax to communicate with my post controller.

    @using (Html.BeginForm("Index", "Directory", FormMethod.Post))
    {
        <p>
            Search Employee: <input type="text" name="userName" onkeyup="filterTerm(this.value);" />


        </p>

    }

<script>
    function filterTerm(value) {
        $.ajax({
            type: "POST",
            url: '@Url.Action("Index","Directory")',
            data: JSON.stringify({ userName: value }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                $("#senderContent").html(msg.toString);
            },
            error: function () {
                alert("not connected!");
            }
        });
    }
</script>

and this is my controller:

        [HttpPost]
        public ActionResult Index(string userName)
        {
        /**********Establish Connection********/
        DirectoryEntry dir = createDirectoryEntry();
        DirectorySearcher search = new DirectorySearcher(dir);

        /****Refer to class constructor****/


        /********Create the List to store results in***************/
        List<ADUser> Users = new List<ADUser>();
        string DisplayName = "", SAMAccountName = "", Mail = "", Description = "", Department = "", TelephoneNumber = "", Fax = "";

        /*******Filter parameters************/
        search.Filter = "(&((&(objectCategory=Person)(objectClass=User)))(anr=" + userName + "* ))";
        SearchResultCollection searchresult = search.FindAll();
        search.PropertiesToLoad.Add("Displayname");
        search.PropertiesToLoad.Add("SAMAccountName");
        search.PropertiesToLoad.Add("Mail");
        search.PropertiesToLoad.Add("Description");
        search.PropertiesToLoad.Add("TelephoneNumber");
        search.PropertiesToLoad.Add("Fax");
        search.PropertiesToLoad.Add("Department");

         /*****************Filtering and populating the List****************/    

        if (searchresult != null)
        {
            foreach (SearchResult iResult in searchresult)
            {
                ADUser userAttributes = new ADUser("", "", "", "", "", "", "");

                foreach (string PropertyName in iResult.Properties.PropertyNames)
                {
                    foreach (Object key in iResult.GetDirectoryEntry().Properties[PropertyName])
                    {
                        try
                        {
                            switch (PropertyName.ToUpper())
                            {
                                case "DISPLAYNAME":
                                    DisplayName = key.ToString();
                                    userAttributes.Name = DisplayName;
                                    break;

                                case "SAMACCOUNTNAME":
                                    SAMAccountName = key.ToString();
                                    userAttributes.DomainUserName = SAMAccountName;
                                    break;

                                case "MAIL":
                                    Mail = key.ToString();
                                    userAttributes.EmailAddress = Mail;
                                    break;

                                case "DESCRIPTION":
                                    Description = key.ToString();
                                    userAttributes.JobDescription = Description;
                                    break;

                                case "TELEPHONENUMBER":
                                    TelephoneNumber = key.ToString();
                                    userAttributes.TelephoneNumber = TelephoneNumber;
                                    break;

                                case "FAX":
                                    Fax = key.ToString();
                                    userAttributes.FaxNumber = Fax;
                                    break;

                                case "DEPARTMENT":
                                    Department = key.ToString();
                                    userAttributes.Department = Department;
                                    break;
                            }
                        }
                        catch { }
                    }
                }

                Users.Add(userAttributes);
            }

            return View(Users);
        }
      return View();
     }

I've been monitoring what happens in Fiddler and it doesn't flag an issue, however the ajax error message keeps prompting. I've tested the value before being passed into ajax, and it is reading the value correctly. Just wondering why I'm getting prompted this error. Is it something in my Ajax?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何让企业微信机器人实现消息汇总整合
    • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
    • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
    • ¥15 TLE9879QXA40 电机驱动
    • ¥20 对于工程问题的非线性数学模型进行线性化
    • ¥15 Mirare PLUS 进行密钥认证?(详解)
    • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
    • ¥20 想用ollama做一个自己的AI数据库
    • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
    • ¥15 请问怎么才能复现这样的图呀