c# - asp.net MVC return json -


i use $http request call mvc controller , return data in json format. not able result in javascript/angualr js. return entire html page. made mistake?

myapp.controller('myctrl', ['$scope', '$http', function ($scope, $http) { $scope.toggle = function () {     $http({         url: "/admin/filtermember",         method: "get",         params: { id: $('#txtsearch').val() }     }).then(function (result) {         alert(result);     }); }; }]); 

above angular script in js file.

public actionresult filtermember(string id) {     sqlparameter[] sqlparam = { new sqlparameter("@filter", id) };     datatable dtable = masterminddb.dtablesp(dbconn, "sp_get_memberlist", sqlparam);     list<member> member = new list<member>();      foreach (datarow row in dtable.rows)     {         member.add(new member         {             membername = row["member id"].tostring(),             email = row["email"].tostring(),             joindate = row["join date"].tostring(),             status = row["status"].tostring()         });     }     return view("member", json(member, jsonrequestbehavior.allowget)); } 

above mvc controller

this action filermember view

[httpget] public actionresult filtermember () {     return view(); } 

this action called client side view. no need return viewresult, data

[httpget] public actionresult getmemberbyid(string id) {     sqlparameter[] sqlparam = { new sqlparameter("@filter", id) };     datatable dtable = masterminddb.dtablesp(dbconn, "sp_get_memberlist", sqlparam);     list<member> member = new list<member>();      foreach (datarow row in dtable.rows) {         member.add(new member {             membername = row["member id"].tostring(),             email = row["email"].tostring(),             joindate = row["join date"].tostring(),             status = row["status"].tostring()         });     }     //just return jsonresult.     return json(member, jsonrequestbehavior.allowget); } 

updated client

myapp.controller('myctrl', ['$scope', '$http', function ($scope, $http) { $scope.toggle = function () {     $http({         url: "/admin/getmemberbyid",         method: "get",         params: { id: $('#txtsearch').val() }     }).then(function (result) {         alert(result);     }); }; }]); 

Comments