I'm trying to save data to DB. The breakpoint is not hit in code behind and the data is not saved. All I see in the console log is - PASS : [object Object]. Where am i going wrong.
default.aspx:
<div data-ng-controller="defaultCtrl">
Username
<input type="text" id="txtUsername" data-ng-model="AdminUser.Username" />
<br />
Password
<input type="text" id="txtPassword" data-ng-model="AdminUser.Password" />
<br />
<button type="submit" data-ng-click="AddUser(AdminUser)">Submit</button>
</div>
default.aspx.cs: class:
public class AdminUser
{
public string Username { get; set; }
public string Password { get; set; }
}
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void AddUser(AdminUser adminUser)
{ --breakpoint set here but not hit
--code to save data
AdminUserDB.AddUser(adminUser);
}
defaultCtrl.js:
app.controller("defaultCtrl",["$scope","DefaultFactory",function ($scope,DefaultFactory){
$scope.AddUser = function (AdminUser) {
var promise = DefaultFactory.AddUser(AdminUser);
promise.then(function (success) {
console.log("PASS : " + success);
},
function (error) {
console.log("ERR : " + error);
})
}
}]);
defaultFactory.js:
app.factory("DefaultFactory", ["$http", function ($http) {
var Factory = {};
//add new user
Factory.AddUser = function ($params) {
//console.log($params); -- i can see the object with the data in console.
return $http({
url: "http://localhost:49271/default.aspx/AddUser",
method: "GET", --when i put POST here, there is an error in console
data: $params
})
.success(function (data, status) {
})
.error(function (data, status) {
console.log("DATA : " + data);
console.log("STATUS : " + status);
});
};
return Factory;
}]);
<button type="submit" data-ng-click="AddUser(AdminUser)">Submit</button>you don;t need to pass inAdminUserbecause it is attached to your scope, so you just use that in the function.