.field-validation-error {
color: #f00;
} .field-validation-valid {
display: none;
} .input-validation-error {
border: 1px solid #f00;
background-color: #fee;
} .validation-summary-errors {
font-weight: bold;
color: #f00;
} .validation-summary-valid {
display: none;
}

Style.css

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web; namespace PartyInvites.Models
{
public class GuestResponse
{
[Required(ErrorMessage = "Please enter your name")]
public string Name { get; set; }
[Required(ErrorMessage="Please enter your email address")]
[RegularExpression(".+\\@.+\\..+",ErrorMessage="Please enter a valid email address")]
public string Email { get; set; }
[Required(ErrorMessage="Please enter your phone number")]
public string Phone { get; set; }
[Required(ErrorMessage="Please specify whether you'll attend")]
public bool? WillAttend { get; set; }
}
}

Model__GuestResponse.cs

在view文件夹中,Home控制器内存在3个主视图

@{
Layout = null;
} <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/bootstrap-theme.css" rel="stylesheet" />
<title>Index</title>
<style>
.btn a {
color: white;
text-decoration: none;
} body {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<div class="text-center">
<h2>We're going to have an exciting party.<br />(To do: sell it better. Add pictures or something.)</h2>
<h3>And you are invited</h3>
<div class="btn btn-success">
@Html.ActionLink("RSVP Now", "RsvpForm")
</div>
</div>
</body>
</html>

View→Home→Index.cshtml

@model PartyInvites.Models.GuestResponse

@{
Layout = null;
} <!DOCTYPE html> <html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/bootstrap-theme.min.css" rel="stylesheet" />
<link href="~/Content/style.css" rel="stylesheet" />
<title>RsvpForm</title>
</head>
<body>
<div class="panel panel-success">
<div class="panel-heading text-center"><h4>RSVP</h4></div>
<div class="panel-body">
@using (Html.BeginForm())
{
@Html.ValidationSummary()
<div class="form-group">
<label>Your name:</label> @Html.TextBoxFor(x => x.Name, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Your email:</label> @Html.TextBoxFor(x => x.Email, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Your phone:</label> @Html.TextBoxFor(x => x.Phone, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Will you attend?</label>
@Html.DropDownListFor(x => x.WillAttend, new[]{
new SelectListItem(){Text="Yes,I'll be there",Value=bool.TrueString},
new SelectListItem(){Text="No,I can't come",Value=bool.FalseString}
}, "Choose an option", new { @class = "form-control" })
</div>
<div class="text-center"><input class="btn btn-success" type="submit" name="name" value="Submit RSVP" /></div>
}
</div>
</div>
</body>
</html>

View→Home→RsvpForm.cshtml

@model PartyInvites.Models.GuestResponse

@{
Layout = null;
} <!DOCTYPE html> <html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Thanks</title>
</head>
<body>
<div>
<h1>Thank you,@Model.Name!</h1>
@if (@Model.WillAttend == true) {
@:It's great that you're coming.The drinks are already in the fridge.
}
else {
@:Sory to hear that you can't make it,but thanks for letting us know.
}
</div>
</body>
</html>

View→Home→Thanks.cshtml

controller

using PartyInvites.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc; namespace PartyInvites.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
//public ActionResult Index()
//{
// return View();
//}
public ViewResult Index() {
int hour = DateTime.Now.Hour;
ViewBag.Greeting = hour < ? "Good Morning" : "Good Afternoon";
return View();
}
public ViewResult RsvpForm() {
return View();
}
[HttpPost]
public ViewResult RsvpForm(GuestResponse guestResponse)
{
if (ModelState.IsValid)
{
return View("Thanks", guestResponse);
}
else {
return View();
}
}
}
}

HomeController.cs

最新文章

  1. Carousel 旋转画廊特效的疑难杂症
  2. MAC上显示隐藏文件夹
  3. java 接口中模拟浏览器 请求webservice 接受返回数据
  4. super和this区别
  5. bzoj 2818: Gcd GCD(a,b) = 素数
  6. 关于版本号:alpha、beta、rc、stable
  7. 【Struts 2】Struts2环境搭建
  8. css 多行显示省略号....
  9. 论游戏中Buff的实现 [转]
  10. unix IO笔记
  11. tensorflow官方文档中的sub 和mul中的函数已经在API中改名了
  12. 如何访问pcie整个4k的配置空间
  13. [转]Java GC的原理
  14. 04_web基础(八)之车票实现增删改查初级版本
  15. 谷歌地图api访问失败
  16. 目前主流编译器对C++11特性的支持情况
  17. Mac安装软件时提示已损坏的解决方法
  18. psoc做dds
  19. 浅谈对js原型的理解
  20. Bootstrap教程目录

热门文章

  1. CF407D Largest Submatrix 3
  2. loj 6031「雅礼集训 2017 Day1」字符串
  3. springboot(十七)-使用Docker部署springboot项目
  4. CentOS7部署HDP3.1.0.0
  5. 原生js和css写虚拟键盘
  6. mysql 5.7.24 root密码重置
  7. uestc summer training #9 牛客第三场 BFS计数
  8. [转帖]微軟将从 .NET 4 以后的版本弃用 System.Data.OracleClient
  9. 拖动元素,自由变换位置 jquery
  10. Acwing-283-多边形(区间DP)