我試圖從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');
}
}
試試這個'var allEmployees = $ http.post('Controllers/Admin/GetUsers');' – gypsyCoder
你得到了什麼錯誤? – user449689