我需要从角度js $ http url调用Initailly参数化构造函数,该函数映射MVC中的action方法。 我的角度js控制器代码如下: -
var app = angular.module("ourSiteLogIn", []);
app.controller("ourSiteLogInController", function ($scope, $http) {
$scope.GetLogInByUserIdPassword = function () {
$http({
method: "POST",
url: "User/GetLogInByUserIdPassword",
params: {
UserId: $scope.UserId,
Password: $scope.Password
}
}).then(function mySuccess(response) {
$scope.User = response.data;
}, function myError(reason) {
$scope.error = reason.data;
});
};
});
下面是我的控制器:
public class UserController : Controller
{
private readonly ILogIn _login;
private readonly IExceptionLog _exceptionlog;
public UserController()
{
}
public UserController(ILogIn login, IExceptionLog exceptionLog)
{
_login = login;
_exceptionlog = exceptionLog;
}
[HttpPost]
public JsonResult GetLogInByUserIdPassword(string UserId, string Password)
{
try
{
Encrypt objEncrypt = new Encrypt();
tblLogIn objtblLogIn = new tblLogIn();
objtblLogIn = _login.GetLogInByUserIdPassword(UserId, objEncrypt.EncryptText(Password));
return Json(objtblLogIn, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
_exceptionlog.insertExceptionLog(ex);
return null;
}
}
}
这里的问题是我在调用此方法时将_login作为空值" GetLogInByUserIdPassword"这个方法在另一个项目中有用。默认情况下,它调用默认构造函数但不调用参数化构造函数。任何想法都将不胜感激。谢谢。