2016-10-04 178 views
0

我試圖從server.Get用戶函數獲取數據,我試圖將它傳遞給AdminController.js。我究竟做錯了什麼? 我收到此錯誤:類型錯誤:無法讀取屬性未定義角從服務器獲取數據MVC

namespace VTS.Controllers 
{ 
    public class AdminController : Controller 
    { 
     public ActionResult Index() 
     { 
      return View(); 
     } 

     [HttpPost] 
     public JsonResult GetUsers() 
     { 
      JavaScriptSerializer jss = new JavaScriptSerializer(); 
      var jsonString = string.Empty; 
      TributaryEntities db = new TributaryEntities(); 
      var listUsers = (from user in db.PSP_BatchOrderDriver select new { ID = user.ID, Fname = user.FirstName, LastName = user.LastName }).ToList(); 
      string output = jss.Serialize(listUsers); 
      var test = Json(jss.Serialize(output)); 
      return test; 
     } 
    } 
} 

AdminController.js的 '後' 文件

'user strict'; 
myApp.controller('AdminController', 

function AdminControllerl($timeout, $q, $log) 
{ 
    var self = this; 

    self.simulateQuery = false; 
    self.isDisabled = false; 

    self.employees = loadAll(); 

    function loadAll($http) 
    { 
     var allEmployees = $http.post('Controllers/AdminController/GetUsers'); 
    } 
} 
+0

試試這個'var allEmployees = $ http.post('Controllers/Admin/GetUsers');' – gypsyCoder

+0

你得到了什麼錯誤? – user449689

回答

1

嘗試包括 '$ HTTP' 在控制器的參數

'user strict'; 
myApp.controller('AdminController', 

function AdminControllerl($timeout, $q, $log, $http) 
{ 
    var self = this; 

    self.simulateQuery = false; 
    self.isDisabled = false; 

    self.employees = loadAll(); 

    function loadAll() 
    { 
     var allEmployees = $http.post('Controllers/AdminController/GetUsers'); 
    } 
} 
+0

謝謝,但我得到了同樣的錯誤:'不能讀取'undefined' – user6440175

+0

的屬性'post'也從loadAll函數定義中刪除'$ http' – prasanna

+0

謝謝。它的工作,但現在我找不到'Controllers/AdminController/GetUsers'的路徑 – user6440175