Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello friends

I wanted to ask how I can return data with angularjs using webmetod and ajax
I've seen people do it in asp - MVC pattern. but I want to do it with asp normal

This code does not work for me :

MyPage
C#
public partial class WebForm1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    
    }
    
    [WebMethod]
    public static List<Student> GetStudent()
    {
        List<Student> lstStudents = new List<Student>()

MyApp
JavaScript
var app = angular.module('app', ['ngResource']);

app.controller('studentsCtrl', function ($scope, student) {
    $scope.student = student;
});

app.value('pageMethods', PageMethods);

app.factory('student', function (pageMethods, $rootScope) {
    var result = [];
    pageMethods.GetStudent(function (data) {
        data.forEach(function (item) {
            result.push({ id: item.id, name: item.name});
        });
        $rootScope.$apply();
    });
    return result;
})
Posted
Updated 15-May-15 4:54am
v2

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