我AngularJs POST請求:後數據使用AngularJS到MVC上Service.js 2.0
this.Add = function (employee) {
var response = $http({
method: "post",
url: "/Employee/Add",
data: JSON.stringify(employee),
dataType: "json",
});
return response;
}
我莫代爾類:
[Serializable]
public class Employee
{
public Employee()
{ }
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
}
添加EmployeeController的方法:
[HttpPost]
public string Add(Employee employeeNew)
{
if (employeeNew != null)
{
unitOfWork.EmployeeRepository.Insert(employeeNew);
unitOfWork.Save();
return "Record has been Added";
}
else
{
return "Record has Not been Verified";
}
}
我使用MVC 2.0。當我在上面提出請求時,Add方法中的Employee類是空的。另一方面,當我查看我的添加請求時,我看到該請求包含名字,姓氏,用戶名和密碼值以及完整的正確數據。如何將這些屬性綁定到Add方法的Employee對象上。
我有同樣的問題..但我從'.apsx'頁面'.cshtml'頁面切換。它解決了我的問題,我知道它不適合做這件事..但仍然這是workaroud –