Guest User

Untitled

a guest
Nov 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. <head>
  2.  
  3. <script>
  4. var app = angular.module("MyApp", []);
  5. app.controller("MyCtrl", function ($scope) {
  6. $scope.Data = function () {
  7. if ($scope.myForm.Name.$valid && $scope.myForm.Email.$valid) {
  8. alert($scope.Name + " " + $scope.Email)
  9. var Details =
  10. {
  11. Name: $scope.Name,
  12. Email: $scope.Email
  13.  
  14. };
  15. debugger;
  16. $.ajax({
  17. type: "POST",
  18. dataType: 'text',
  19. contentType: 'application/json; charset=utf-8',
  20. url: "/Home/AddStudent",
  21. data: JSON.stringify(Details),
  22. success: function (res) {
  23. if (res == "True") {
  24. alert('Information Saved Successfully!');
  25. window.location.assign('/Home/data');
  26. }
  27. else {
  28. window.location.assign('/Home/data');
  29. alert('Some Error occurred!');
  30. }
  31. },
  32. error: function (xhr, textStatus, errorThrown) {
  33. alert('Some Error occurred!');
  34. }
  35. });
  36. }
  37. }
  38. });
  39. </script>
  40. <style>
  41. input.ng-invalid
  42. {
  43. background-color:red;
  44. }
  45. input.ng-valid
  46. {
  47. background-color:greenyellow;
  48. }
  49. </style>
  50. </head>
  51. <body ng-app="MyApp" ng-controller="MyCtrl">
  52.  
  53. <p>Try writing in the input field:</p>
  54. <form action="/" method="post" name="myForm">
  55. <table>
  56. <tr>
  57. <td>Name: </td>
  58. <td><input data-val="true" data-val-required="Name is required" id="Name" name="Name" ng-model="Name" required="required" type="text" /></td>
  59. </tr>
  60. <tr>
  61. <td>Email: </td>
  62. <td><input data-val="true" data-val-required="Email is required" id="Email" name="Email" ng-model="Email" required="required" type="text" /></td>
  63. </tr>
  64.  
  65. </table>
  66. <p>The input's valid state is:</p>
  67. <h1>{{myForm.Name.$valid}}</h1>
  68.  
  69.  
  70. <h1>{{myForm.Email.$valid}}</h1>
  71. <input type="submit" value="Click" ng-click="Data()" />
  72. </form>
Add Comment
Please, Sign In to add comment