Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
In My MVC Web Application I Call Ajax and In Success I have Json Object ,The Json Object Contains list of items ,the length of list is 61111 item but when Trying to append these items to the list one by one using loop it takes long time and then the web page tells me that the page unresponsive kill or continue,
the code as follow

step1:
@Html.ListBox("_TAG_INFO", new MultiSelectList(ViewBag.TAG_INFO_ID, "ID", "ITEM_ID", Model._TAG_INFO.Select(x => x.ID)), new { Multiple = "multiple", @id = "TagsListbox" })

--
Step2:

JavaScript
$.ajax({
            cache: false,
            type: "POST",
            url: "@(Url.Action("GetTags", "TagPath"))",
            data: { "Service": service },
            dataType: 'json',
            success: function (data) {

                $("#TagsListbox").empty();
                for (var i = 0; i < data.objects.length; i++) {


                    //            $.each(data.objects, function (i, item) {
                    var selected = "";
                    if (data.objects[i] != null) {

                        if (data.objects[i]._IsSelected) {
                            selected = "selected";
                        }

                        var newOption = "<option value='" + data.objects[i].ID + "'" + " " + selected + ">" + data.objects[i].ITEM_ID + "</option>";
                        $("#TagsListbox").append(newOption);
                    }
                    //         });
                }
            },
            error: function () {
                alert('@Resource._CantRetData');
            }
        });


-----
step3:
C#
[HttpPost]
       public JsonResult GetTags(string service)
       {
           string strAlert = string.Empty;
           List<TAG_INFO> objects = new List<TAG_INFO>();
           int CurrentBusinessGroup = GetCurrentUserGroup().BUSINESS_GROUP_ID;
           List<TAG_INFO> _TAG_INFO;
           try
           {

               var FilteredTags =new List<TAG_INFO>();

               if (service == "0" || service == null) //All selected
               {
                   _TAG_INFO = db.TAG_INFO.Where(x => x.STATUS == ActiveStatus).ToList();


               }
               else
               {
                   _TAG_INFO = db.TAG_INFO.Where(x => x.SERVICE == service && x.STATUS == ActiveStatus).ToList();
               }

                   if (_TAG_INFO.Count > 0)
                   {
                       //objects.Add(new TAG_INFO() { ID = 0, ITEM_ID = Resource._AllTags });

                       foreach (var item in _TAG_INFO)
                       {
                           objects.Add(new TAG_INFO() { ID = item.ID, ITEM_ID = item.ITEM_ID + "-" + item.ITEM_SUB_ID, _IsSelected = false });
                       }
                   }
           }
           catch (Exception ex)
           {

               strAlert = ex.ToString();
           }

           //Return your JSON object
           JsonResult jsonResult = Json(new { objects = objects, strAlert = strAlert },JsonRequestBehavior.AllowGet);
           jsonResult.MaxJsonLength = int.MaxValue;
           return jsonResult;
           //return Json(new { objects = objects, strAlert = strAlert });


       }


What I have tried:

I am trying to append More than Millon record to listBox.
Posted
Updated 3-Mar-16 0:06am
Comments
Maciej Los 3-Mar-16 5:37am    
Why? Such of attempt is for sure the reason of headache!
See: json - how to pagination JSONResult in MVC with ajax url data loading? - Stack Overflow[^]
Member 11979068 3-Mar-16 5:55am    
Dear @Maciej Los,
I already tried to using Paging but when I was trying to search about any item it search about it only on the current page or sublist!
so I can not use Paging in that case.
Richard Deeming 3-Mar-16 5:50am    
Do you seriously think your users are going to scroll through 1,000,000 records to find the one they want?

If they can look at one record a second, without taking a break, it would take them 11 days 13 hours and 47 minutes to work their way though that list.

Find a way to filter the list so that the user can find the item they want without having to scroll through such an enormous list.
Member 11979068 3-Mar-16 5:58am    
I have Search in the listbox control but when I tried to use paging I faced a problem in the search , it search only in the items of the current page not all the list.
Maciej Los 3-Mar-16 7:33am    
My favorite comment of this day. I'm wondering how you were able to count the exact time needed to upload data ;)

1 solution

Quote:
I am trying to append More than Million record to listBox.
Absolutely avoid this.
There is no solution to fast add a million lines to listbox.
You have to find another way that fit the needs.

Think about what append when you search on facebook or google: you begin to type something and a dropbox begin to display some proposals on fly.

You should explain what is the list, we may have better idea of how to deal with it.
 
Share this answer
 
v2
Comments
Maciej Los 3-Mar-16 7:30am    
5ed!
Patrice T 3-Mar-16 9:25am    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900