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 GEO下载数据的处理报错 :函数‘Meta’标签‘"data.frame"’找不到继承方法,如何解决?
      • ¥15 DLNM模型是否可以用二分类变量作为y变量
      • ¥15 android object box 一个实体多个表怎么写
      • ¥15 temux 启用docker 服务失败
      • ¥15 Flask 使用celery发送邮件出现‘目标计算机积极拒绝‘
      • ¥60 老人用的sd卡在手机里面不知道操作了什么,导致图片和视频变成了文件,取下sd卡连接电脑就是图中的样子,后缀改为.jpg才可以,需要用系统的画图软件才能打开,文件属性还是文件,有没有批量操作的解决办法
      • ¥15 超时跳出方法代码的返回值问题
      • ¥15 汇编语言程序设计设计,ascii码求数,再求数的BCD码
      • ¥30 Mask rcnn训练自己的数据集出现问题!
      • ¥20 研究人工智能时的几个问题