[RESOLVED]how to pass data from database in controller to view with ajax

Hi Friends . . .

how i can return data from controller to view with ajax ( Json ), i use following code but this code not run , if i change following  fun to ( public string GetChoices() { return " Test "; } )

Ajax return me " Test " , but i want return array of value . . . 

AccountController :

        public IEnumerable<TblArticle> GetChoices()
        {
            var fb = new DataBaseContext();
            var data = from item in fb.TblArticles select item;
            return data;
        }

JavaScript :

function ReturnData() {
    $.ajax({
        type: "Post",
        url: "GetChoices/Account",
        contentType: "application/json;charset=utf-8",
        datatype: "json",
        success: function (results) {
            for (var i = 0; i < results.d.length; i++) {
                $("#container").append("<div data-questions-questionid='" + results.d[i].QuestionID + "'>" + results.d[i].QuestionText + "</div>");
                $("div[data-questions-questionid]").addClass("paddedDiv");
            }
        },
        error: function (err) {
            alert(err.status + " - " + err.statusText);
        }
    });
}

View :

    <input type="submit" value="Test" onclick="GetChoices"/>

gave me a example or link for this fun . . .

help me please. . .

Leave a Reply