阿贾克斯没有更新我的搜索列表 [英] Ajax not updating my search list

查看:100
本文介绍了阿贾克斯没有更新我的搜索列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MVC 5 C#和我试图通过AJAX击键更新我的搜索过滤器。通过code它的工作原理,但结果没有显示出来的测试。我做了一些调试,在我看来,结果被扔在视图中,如下所示:

I'm using MVC 5 C# and I'm trying to update my search filter on key strokes through AJAX. By code it works but the results aren't showing up on testing. I've done some debugging and in my view the results are being thrown in the view as shown:

这应该右边的搜索框下方将显示,但说明不了什么。

It's supposed to be displayed right underneath the search box but shows nothing.

不太清楚是什么问题。所以我会列出我的code。这是我的Ajax。

Not quite sure what the issue is. So I'll list my code. Here is my Ajax.

<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: {
                userName: value
            },
            cache: false,
            success: function (result) {


            }
        });
    }
</script>

阿贾克斯已经过测试,工作正常,现在在我的控制器也将返回结果(显然被拉回看法,但只是显示的结果)。 但这里是我的控制器反正:

Ajax has been tested and is working, now in my controller it also is returning results (obviously is being pulled back to the View but just showing results). But here is my controller anyways:

[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())
                        {
                              .....
                        }
                    }
                    catch { }
                }
            }

            Users.Add(userAttributes);
        }

        return View(Users);
    }

    return View();
}

看起来这可能仅仅是我丢失的东西,我不知道。 任何帮助将大大AP preciated。

It seems like it might just be something I'm missing that I don't know about. Any help would be greatly appreciated.

干杯

推荐答案

你的用户列表序列化到JSON之前它返回到浏览如下。

serialize your user list to json before return it to view as follow.

 using System.Web.Script.Serialization;

var jsonSerialiser = new JavaScriptSerializer();
var json = jsonSerialiser.Serialize(User);
return View(json)

和让你的AJAX的数据类型JSON如下:

and make your ajax's datatype json as follow :

 $.ajax({
            type: "POST",
            url: '@Url.Action("Index", "Directory")',
            data: {
                userName: value
            },
            dataType:"json",
            cache: false,
            success: function (result) {


            }
    });

这篇关于阿贾克斯没有更新我的搜索列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆