我有一個類如何通過類對象angularjs功能
public class Customer
{
private int _Id;
public int Id
{
get { return _Id; }
set { _Id = value; }
}
private String _Name;
public String Name
{
get { return _Name; }
set { _Name = value; }
}
private String _Address;
public String Address
{
get { return _Address; }
set { _Address = value; }
}
}
我需要使用這個類來保存數據。我需要知道如何調用這個類中的數據功能
$scope.Save = function() {
var httpreq = {
method: 'POST',
url: 'ajs.aspx/Save',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'dataType': 'json'
},
data: { //** Here How to call assign object value for my customer class **// }
}
$http(httpreq).success(function (response) {
alert("Saved successfully.");
})
};
如何創建類對象,併爲我的客戶類在這個數據部分指定值。
在我的Web方法
[System.Web.Services.WebMethod()]
public static void Save(Customer objcsr)
{
using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
cmd.CommandText = "insert into customer (Name, Address) values (@Name, @Address);";
cmd.Parameters.AddWithValue("@Name", objcsr.Name);
cmd.Parameters.AddWithValue("@Address", objcsr.Address);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
可能重複的[從Angular發佈到.net WebAPI](http://stackoverflow.com/questions/16621706/posting-from-angular-to-net-webapi) –