2

Whenever i return a list collection from a controller through Json. Im unable to get that list but if i just return a string from controller its working fine. In View i have

    <script type="text/javascript" language="javascript">
        $(function () {
            $('#btnFillList').click(function () {
                alert("btnclick");

                var URL = '<%= Url.Action("JsonFunc2","Customer") %>';
                $.post(URL, null, function (data) {
                    for (var i = 0; i < data.length; i++) {
                    }

                });
            });
        });      
    </script>

<input type="submit" id="btnFillList" value="Load" />

In Controller i have

public ActionResult JsonFunc2()
        {

            var cust = _db.tblCustomers.ToList();
            return Json(cust);
        }
1
  • Did any of the answers given below worked?? Commented Jun 2, 2010 at 16:28

2 Answers 2

1

Try returning an array instead of list:

var cust = _db.tblCustomers.ToArray();
return Json(cust);
Sign up to request clarification or add additional context in comments.

Comments

0

Try using eval(data) before looping

 $.post(URL, null, function (result) {
       var data = eval('(' + result + ')');
       for (var i = 0; i < data.length; i++) {

       }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.