Guest User

Untitled

a guest
Jul 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.ComponentModel.DataAnnotations;
  7.  
  8. namespace MyApp.ViewModels
  9. {
  10. public class ContactViewModel
  11. {
  12. [Required]
  13. public string Name { set; get; }
  14.  
  15. [Required]
  16. [EmailAddress]
  17. public string Email { set; get; }
  18.  
  19. [Required]
  20. [StringLength(4096, MinimumLength =10)]
  21. public string Message { set; get; }
  22. }
  23. }
  24.  
  25. @model MyApp.ViewModels.ContactViewModel
  26. @{
  27. ViewBag.Title = " Contact Page ";
  28. }
  29.  
  30.  
  31. @section scripts {
  32. <script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
  33. <script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
  34. }
  35.  
  36. <h2>Contact me</h2>
  37. <div asp-validation-summary="ModelOnly"></div>
  38. <label asp-for="Name"></label>
  39. <input asp-for="Name"/>
  40. <span asp-validation-for="Name" ></span>
  41.  
  42. <label asp-for="Email" ></label>
  43. <input asp-for="Email" type="email"/>
  44. <span asp-validation-for="Name"></span>
  45.  
  46. <label asp-for="Message" ></label>
  47. <textarea cols="40" rows="4" asp-for="Message" ></textarea>
  48. <span asp-validation-for="Name"></span>
  49.  
  50. <div>
  51. <input type ="submit" value="Send Message"/>
  52. </div>
  53.  
  54. @model MyApp.ViewModels.ContactViewModel
  55. @using (Html.BeginForm(new { id = "MyForm" }))
  56. {
  57. @Html.LabelFor(m => m.Name)
  58. @Html.EditorFor(m => m.Name)
  59. @Html.ValidationMessageFor(m => m.Name)
  60.  
  61. @Html.LabelFor(m => m. Email)
  62. @Html.EditorFor(m => m. Email)
  63. @Html.ValidationMessageFor(m => m. Email)
  64.  
  65. @Html.LabelFor(m => m.Message)
  66. @Html.EditorFor(m => m.Message)
  67. @Html.ValidationMessageFor(m => m.Message)
  68.  
  69. <br />
  70. <input type="submit" value="Submit" />
  71. }
  72.  
  73. [Required(ErrorMessage = "Please enter the Name.")]
  74. public string Name { get; set; }
Add Comment
Please, Sign In to add comment