Guest User

Untitled

a guest
Nov 5th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. public class Employee
  2. {
  3. [Key]
  4. public long AutoId { get; set; }
  5.  
  6. [Required]
  7. Display(Name = "Employee ID")]
  8. public string EmployeeId { get; set; }
  9.  
  10. [Required]
  11. [DataType(DataType.Password)]
  12. [Display(Name = "Password")]
  13. public string EmployeePassword { get; set; }
  14. public string FirstName { get; set; }
  15. public string LastName { get; set; }
  16. public string MiddleName { get; set; }
  17. }
  18.  
  19. $(function () {
  20. ko.applyBindings(LoginVm);
  21. });
  22.  
  23. //VIEW MODEL. MODEL IS BELOW THIS
  24. var LoginVm = {
  25.  
  26. thisEmp: ko.observable(EmpObject),
  27.  
  28. LogUser: function () {
  29. var self = this;
  30.  
  31. //trying to check if thisEmp properties has values by alerting
  32. alert("ID: " + thisEmp.EmployeeId() + " Password: " + thisEmp.EmployeePassword());
  33.  
  34. $.ajax({
  35. url: '/Employee/AuthenticateUser',
  36. type: 'POST',
  37. dataType: 'json',
  38. data: ko.toJSON(thisEmp),
  39. contentType: 'application/json',
  40. success: function (errorMsg) {
  41. if (errorMsg === '') {
  42.  
  43. }
  44. }
  45. });
  46.  
  47.  
  48. }
  49. };
  50.  
  51. //MODEL
  52. var EmpObject = {
  53. EmployeeId: ko.observable(''),
  54. EmployeePassword: ko.observable('')
  55. }
  56.  
  57. @using (Html.BeginForm()) {
  58. @Html.ValidationSummary(true)
  59.  
  60. <fieldset>
  61. <legend>Employee</legend>
  62.  
  63. <div class="editor-label">
  64. @Html.LabelFor(model => model.EmployeeId)
  65. </div>
  66. <div class="editor-field">
  67. @Html.TextBoxFor(model => model.EmployeeId, new { data_bind="value: thisEmp.EmployeeId()"})
  68. @Html.ValidationMessageFor(model => model.EmployeeId)
  69. </div>
  70.  
  71. <div class="editor-label">
  72. @Html.LabelFor(model => model.EmployeePassword)
  73. </div>
  74. <div class="editor-field">
  75. @Html.PasswordFor(model => model.EmployeePassword, new { data_bind="value: thisEmp.EmployeePassword()"})
  76. @Html.ValidationMessageFor(model => model.EmployeePassword)
  77. </div>B
  78.  
  79. <p>
  80. @*<input type="submit" value="Create"/>*@
  81. <input type="button" value="Login" data-bind="click: LogUser"/>
  82. </p>
  83. </fieldset>
  84. }
  85.  
  86. Uncaught TypeError: Unable to process binding "value: function (){return thisEmp().EmployeeId }"
  87. Message: Cannot read property 'EmployeeId' of undefined
  88. at value (eval at createBindingsStringEvaluator
Add Comment
Please, Sign In to add comment