MVCコントローラスクリプトのgetメソッドをcshtmlファイルに記述したcshtmlビューページを作成しました。ボタンをクリックするとボタンRegister New User
が置かれました。これは、$state.go
を使用したHTMLページを登録するためにリダイレクトする必要があります。私はapp.js
とregister.jsという名前のモジュールを作成して、APIコントローラのポストメソッドレジスタを呼び出しました。 問題はRegister New User
ボタンをクリックすることでページがRegister.html
にリロードされないことです。 誰かが CSHTMLコード 私はangularjsを使用してWeb APIプロジェクトを作成しました
<input id="Password" type="text" ng-model="Emp.Password" placeholder="Password" required /></br>
<input type="submit" value="Login" /></br>
<input type="reset" value="Reset" /></br>
</div>
<input type="button" ng-click="Register()" value="Register New User" />
</div>
</body>
</html>
<script>
// var myapp = angular.module("myApp", ['ui.router']);
(function (app) {
'use strict';
app.controller("LoginController", ["$scope", "$http", "$location", "$window", "$state", function ($scope, $http, $location, $window, $state) {
$scope.Emp = {};
console.log("cont mvc");
$scope.Submit = function (Emp) {
console.log("inside", $scope.Emp);
$http({
method: "POST",
url: '/Webapplication2/Test/Login',
data: $scope.Emp,
})
.then(function successCallback(response) {
console.log("response", response.data);
//$window.location.href = '/Home/Display';
if (response.data == "CORRECT UserName and Password") {
console.log("if condition")
alert("CORRECT UserName and Password");
//$state.go("Display");
//$window.location.href = '/WebApplication2/Test/Display';
$window.alert("Hello " + $scope.Emp.UserName);
}
else if (response.data == "INCORRECT UserName or Password") {
alert("INCORRECT UserName or Password");
}
})
}
$scope.Register = function() {
console.log("reg button");
$state.go('Register');
//$window.location.href = '/Webapplication2/Test/Register';
}
}]);
})(angular.module('myApp', ['ui.router']));
</script>
モジュールapp.jsコードこの問題で私を助け
(function(){ 'use strict'; (); Register.jsはコード (機能(アプリ) {
console.log("cont register");
app.controller("RegisterController", function ($scope, $http, $location, $window,$state) {
console.log("cont2");
$scope.Submit = function (Emp) {
console.log("inside", Emp);
$http({
method: "POST",
url: '/Webapplication2/Test/Register',
data: $scope.Emp,
})
.then(function (response) {
//$window.location.href = '/Webapplication2/Test/Display';
//$msgbox.alert("Hello " + $scope.Emp.UserName);
$window.alert("Hello " + $scope.Emp.UserName);
})
}
$scope.Login = function() {
console.log("login button")
$state.go('Login');
//$window.location.href = '/Webapplication2/Test/Login';
}
});
})(angular.module('myApp',[]));
登録ああ起こって?コンソールエラーはありませんか? –