Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.ComponentModel.DataAnnotations;
- namespace MyApp.ViewModels
- {
- public class ContactViewModel
- {
- [Required]
- public string Name { set; get; }
- [Required]
- [EmailAddress]
- public string Email { set; get; }
- [Required]
- [StringLength(4096, MinimumLength =10)]
- public string Message { set; get; }
- }
- }
- @model MyApp.ViewModels.ContactViewModel
- @{
- ViewBag.Title = " Contact Page ";
- }
- @section scripts {
- <script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
- <script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
- }
- <h2>Contact me</h2>
- <div asp-validation-summary="ModelOnly"></div>
- <label asp-for="Name"></label>
- <input asp-for="Name"/>
- <span asp-validation-for="Name" ></span>
- <label asp-for="Email" ></label>
- <input asp-for="Email" type="email"/>
- <span asp-validation-for="Name"></span>
- <label asp-for="Message" ></label>
- <textarea cols="40" rows="4" asp-for="Message" ></textarea>
- <span asp-validation-for="Name"></span>
- <div>
- <input type ="submit" value="Send Message"/>
- </div>
- @model MyApp.ViewModels.ContactViewModel
- @using (Html.BeginForm(new { id = "MyForm" }))
- {
- @Html.LabelFor(m => m.Name)
- @Html.EditorFor(m => m.Name)
- @Html.ValidationMessageFor(m => m.Name)
- @Html.LabelFor(m => m. Email)
- @Html.EditorFor(m => m. Email)
- @Html.ValidationMessageFor(m => m. Email)
- @Html.LabelFor(m => m.Message)
- @Html.EditorFor(m => m.Message)
- @Html.ValidationMessageFor(m => m.Message)
- <br />
- <input type="submit" value="Submit" />
- }
- [Required(ErrorMessage = "Please enter the Name.")]
- public string Name { get; set; }
Add Comment
Please, Sign In to add comment