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. . .
I googled "call mvc action from ajax" and here are some of the results
http://bobcravens.com/2009/11/ajax-calls-to-asp-net-mvc-action-methods-using-jquery/