Pass (Send) List from Controller to View using jQuery AJAX in ASP.Net MVC

Last Reply 7 months ago By dharmendr

Posted 7 months ago

Dear Brother

I create progran (token number) and y now this use in counter

        public JsonResult btnPrintToken()
        {           
            if (Session["Tokenqueu"] == null)
            {
                Queue<int> queueToken = new Queue<int>();
                Session["Tokenqueu"] = queueToken;
            }
            List<int> listnumbertoken = new List<int>();
            Queue<int> tokenQueue = (Queue<int>)Session["Tokenqueu"];
            //string mesg = "There are" + tokenQueue.Count.ToString() + "Customer in the queue before you";
           if(Session["Lastnumbertoken"] == null)
            {
                Session["Lastnumbertoken"] =0;
            }
            int nextnumbertoken = (int)Session["Lastnumbertoken"] + 1;
            Session["Lastnumbertoken"] = nextnumbertoken;
            tokenQueue.Enqueue(nextnumbertoken);

            foreach(int token in tokenQueue)
            {               
                listnumbertoken.Add(token);
            }
            
            return Json(listnumbertoken, JsonRequestBehavior.AllowGet);
        }

 

    <script type="text/javascript">
        $(document).ready(function () {
            $('#btnPrintToken').click(function () {
                $.ajax({
                    url: '@Url.Action("btnPrintToken", "token")',
                    type: 'GET',
                    dataType: 'json',
                    success: function (N) {
                        $(N).each(function (x) {
                        listTokens.append($('<option/>', x));
                        });
                    },
                });
            });
        });
    </script>

how get this list intger in json and read in my list html

thanks

This question does not have replies that have been liked.