【发布时间】:2020-02-19 06:53:32
【问题描述】:
尊敬的社区, 我在将我的角度 js 控制器重定向到 c# 控制器时遇到问题。下面是我的脚本控制器代码和 c# 控制器代码。我在 url 中犯了任何错误,或者是否需要任何路由将我的角度控制器带到 c# 控制器。当控制器被击中,它立即调用带有错误警报的错误回调。请给我一个解决方案。
角度控制器代码:
var httpTimeout = 1800000;
var httpTimeoutSearch = 3600000;
angular.module('MyApp', [])
var app = angular.module('myApp', []);
app.controller('LoginController', ['$scope', '$rootScope', '$http', function ($scope, $rootScope, $http) {
$scope.username = "";
$scope.password = "";
$scope.Login = function () {
if ($scope.username != null && $scope.username != "") {
if ($scope.password != null && $scope.password != "") {
try {
$http({
method: 'POST',
url: '/Account/Maxi',
data: { Username: $scope.username, Passord: $scope.password },
timeout: httpTimeout,
}).then(function successCallback(response) {
alert("sucess");
}, function errorCallback(response) {
alert("error");
});
}
catch (ex)
{ alert(ex); }
}
}
}
}]);
我的 C# 控制器代码:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Maxi(LoginModel data, string returnUrl)
{
string strReturn = "";
string ConStr = "";
string Code = "";
if (data.UserName != null)
{
if (data.Password != null)
{
DataSet ds = new DataSet();
SqlParameter[] parameters =
{
new SqlParameter( "@name", SqlDbType.VarChar, 20) { Value = data.UserName } ,
new SqlParameter("@Roll_No", SqlDbType.Int) { Value = data.Password } ,
};
ConStr = "Data Source=" + "192.168.1.9" + ";Initial Catalog=" + "MyFistDataBase" + ";User id=" + "sa" + ";Password=" + "123" + ";";
using (SqlConnection con = new SqlConnection(ConStr))
{
using (SqlCommand cmd = new SqlCommand("Maxi", con))
{
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
cmd.Parameters.AddRange(parameters);
da.SelectCommand = cmd;
da.Fill(ds);
}
}
string errmsg = "";
if (errmsg != "")
{
Code = "0"; strReturn = errmsg;
}
else
{
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
Code = "1";
foreach (DataRow dr in ds.Tables[0].Rows)
{
strReturn += dr[0].ToString();
}
if (strReturn == "1")
{
Console.Write("Updated");
}
}
//TripDT = TripDT.ToShortDateString();
}
}
}
}
return View(data);
}
【问题讨论】:
标签: javascript c# angularjs asp.net-mvc