. .
MVC , . , , .
ASP.NET MVC , System.ComponentModel.DataAnnotations, , C#. , GuestResponse:
using System.ComponentModel.DataAnnotations; namespacePartyInvites.Models{publicclassGuestResponse { [Required(ErrorMessage=", ")]publicstring Name { get; set; } [Required(ErrorMessage=", email")][RegularExpression(".+\\@.+\\..+", ErrorMessage=" email")]publicstring Email { get; set; } [Required(ErrorMessage = ", ")]publicstring Phone { get; set; } [Required(ErrorMessage = ", , ")]publicbool? WillAttend{ get; set; }}}MVC . , , , , .
, WillAttend , null. , Required. , , true false, , . , null, : true, false null. null , , Required . , MVC Framework C# HTML HTTP.
ModelState.IsValid . , RsvpForm, POST, Home:
//... [HttpPost]publicViewResultRsvpForm(GuestResponse guest){if (ModelState.IsValid) // // . returnView("Thanks", guest);else // 蠠 returnView();}, MVC, Thanks, . RsvpForm View() .
|
|
, , - , , . Html.ValidationSummary() RsvpForm, :
@model PartyInvites.Models.GuestResponse @{ Layout = null;} <!DOCTYPE html> <html><head><metaname="viewport"content="/><title>RsvpForm</title></head><body> @using (Html.BeginForm()) { @Html.ValidationSummary() <p>: @Html.TextBoxFor(x =>x.Name)</p><p> email: @Html.TextBoxFor(x =>x.Email)</p><p> : @Html.TextBoxFor(x =>x.Phone)</p><p>? @Html.DropDownListFor(x =>x.WillAttend, new[] {newSelectListItem() { Text = ", ", Value = Boolean.TrueString},newSelectListItem() { Text = ", ", Value = Boolean.FalseString} })</p><inputtype="submit"value=" RSVP" />}</body></html>Html.ValidationSummary() . MVC , . :
Thanks , , GuestResponse. , . , , .
ASP.NET WebForms, , WebForms , , _VIEWSTATE. ASP.NET MVC , ViewState, WebForms. ASP.NET MVC _VIEWSTATE HTML-.