我試圖創建簡單的表單,它將變量傳遞給C#方法,然後將數據庫添加到數據庫。在angularjs中調用c#函數
public static bool Add(string username, string password, string email, string ip)
{
User newUser = new User { id = HomeController.db.Users.Count() + 1, createdOn = DateTime.Now, email = email, ipAddress = ip, isDeleted = false, password = password, username = username, info = new AdditionalInfo(), notices = new List<Notice>() };
newUser.address.user = newUser;
if (!HomeController.db.Users.ToArray().Contains(newUser, new EqualByData()))
{
HomeController.db.Users.Add(newUser);
HomeController.db.SaveChanges();
}
else return false;
return true;
}
這種方法在C:\NTPortal\NTportal\NTportal\Controllers
當我試圖調用它angularjs控制器:
if (!$scope.email_bad && !$scope.pass_bad && !$scope.pass_not_match) {
console.log('no errors')
var Add = function (username, password, email, ip) {
var config = {
params: {
username: username,
password: password,
email: email,
ip: ip
}
}
$http.get('../../Controllers/UserController/Add', config)
.success(function (data) {
if (data) {
alert('Vartotojas priregistruotas');
}
})
.error(function (error) {
alert('Ivyko klaida');
})
}
Add($scope.username, $scope.password, $scope.email, ipAddress);
}
角是C:\NTPortal\NTportal\NTportal\Views\Home
錯誤我得到的,是GET http://localhost:2016/Controllers/UserController.cs/[email protected]&password=bandymas1&username=f 404 (Not Found)
任何幫助將理解
在獲取URL從控制器名稱末尾的」的.cs':'$ HTTP .get('../../ Controllers/UserController/Add',config)' –
試過了,結果相同 –
你可能也想看看解決你的url(例如,讓你的視圖創建一個JavaScript變量來保存解析路徑。var path = @ Url.Action(「Add」,「User」);' –