Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <head>
- <script>
- var app = angular.module("MyApp", []);
- app.controller("MyCtrl", function ($scope) {
- $scope.Data = function () {
- if ($scope.myForm.Name.$valid && $scope.myForm.Email.$valid) {
- alert($scope.Name + " " + $scope.Email)
- var Details =
- {
- Name: $scope.Name,
- Email: $scope.Email
- };
- debugger;
- $.ajax({
- type: "POST",
- dataType: 'text',
- contentType: 'application/json; charset=utf-8',
- url: "/Home/AddStudent",
- data: JSON.stringify(Details),
- success: function (res) {
- if (res == "True") {
- alert('Information Saved Successfully!');
- window.location.assign('/Home/data');
- }
- else {
- window.location.assign('/Home/data');
- alert('Some Error occurred!');
- }
- },
- error: function (xhr, textStatus, errorThrown) {
- alert('Some Error occurred!');
- }
- });
- }
- }
- });
- </script>
- <style>
- input.ng-invalid
- {
- background-color:red;
- }
- input.ng-valid
- {
- background-color:greenyellow;
- }
- </style>
- </head>
- <body ng-app="MyApp" ng-controller="MyCtrl">
- <p>Try writing in the input field:</p>
- <form action="/" method="post" name="myForm">
- <table>
- <tr>
- <td>Name: </td>
- <td><input data-val="true" data-val-required="Name is required" id="Name" name="Name" ng-model="Name" required="required" type="text" /></td>
- </tr>
- <tr>
- <td>Email: </td>
- <td><input data-val="true" data-val-required="Email is required" id="Email" name="Email" ng-model="Email" required="required" type="text" /></td>
- </tr>
- </table>
- <p>The input's valid state is:</p>
- <h1>{{myForm.Name.$valid}}</h1>
- <h1>{{myForm.Email.$valid}}</h1>
- <input type="submit" value="Click" ng-click="Data()" />
- </form>
Add Comment
Please, Sign In to add comment