控制器

 
 

public class NewHomeController : Controller

    {

        // GET: /NewHome/

        public ActionResult Index()

        {

            int hour = DateTime.Now.Hour;

            ViewBag.Greeting = hour < 12 ? "早上好!" : "下午好!";

            return View();

        }

        [HttpGet]

        public ViewResult RsvpForm()

        {

            return View();

        }

  
 

        [HttpPost]

        public ViewResult RsvpForm(GuestResponse guestResponse)

        {

            if (ModelState.IsValid)

            {

                //发送Email

                return View("Thanks", guestResponse);

            }

            else

            {

                return View();

            }       

        }

    }

 
 

视图 Index.cshtml

 
 

@{

    Layout = null;

}

 
 

<!DOCTYPE html>

 
 

<html>

<head>

    <meta name="viewport" content="width=device-width" />

    <title>Index</title>

</head>

<body>

<div>

    @ViewBag.Greeting World(from the view)

    <p>我们将举办一场聚会。</p>

    @Html.ActionLink("RSVP Now","RsvpForm")

</div>

</body>

</html>

 
 

视图 RsvpForm.cshtml

 
 

@model EF6.Models.GuestResponse

@{

    Layout = null;

}

 
 

<!DOCTYPE html>

 
 

<html>

<head>

    <meta name="viewport" content="width=device-width" />

    <title>RsvpForm</title>

    <link rel="stylesheet" type="text/css" href="@Url.Content("~/CSS/Html.error.css")"/>

</head>

<body>

    @using (Html.BeginForm())

    {

        @Html.ValidationMessageFor(x=>x.Name)

        <p>Your name: @Html.TextBoxFor(x => x.Name) </p>

        @Html.ValidationMessageFor(x => x.Email)

        <p>Your email: @Html.TextBoxFor(x => x.Email)</p>

        @Html.ValidationMessageFor(x => x.Phone)

        <p>Your phone: @Html.TextBoxFor(x => x.Phone)</p>

        @Html.ValidationMessageFor(x => x.WillAttend)

        <p>

            Will you attend?

            @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")

        </p>

        <input type="submit" value="Submit RSVP" />

    }

</body>

</html>

 
 

视图 Thanks.cshtml

 
 

@{

    Layout = null;

}

 
 

<!DOCTYPE html>

<html>

<head>

    <meta name="viewport" content="width=device-width" />

    <title>Thanks</title>

</head>

<body>

    <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

    {

        @:Sorry to hear that you can't make it, but thanks for letting us know.

}

</body>

</html>

 
 

 
 

样式 CSS/Html.error.css

 
 

.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}

.field-validation-valid{display: none}

《精通ASP.NET MVC5》第2章 第一个MVC应用程序的更多相关文章

  1. 第六章第一个linux个程序:统计单词个数

    第六章第一个linux个程序:统计单词个数 从本章就开始激动人心的时刻——实战,去慢慢揭开linux神秘的面纱.本章的实例是统计一片文章或者一段文字中的单词个数.  第 1 步:建立 Linu x 驱 ...

  2. 第一章 第一个spring boot程序(转载)

    第一章 第一个spring boot程序 本编博客转发自:http://www.cnblogs.com/java-zhao/p/5324185.html   环境: jdk:1.8.0_73 mave ...

  3. 第一个 MVC 应用程序(上半部分)(《精通 ASP.NET MVC5》 的第二章)

    本章将使用 ASP.NET MVC 框架创建一个简单的数据录入应用程序. 笔者会将过程分解成一个个的步骤,以便能够看出如何构造 ASP.NET MVC 应用程序.(对于一些未进行解释的内容,笔者提供了 ...

  4. ASP.NET MVC5 第4章

    参考资料<ASP.NET MVC5 高级编程>第5版 第4章 模型 本章所探讨的模型是要显示.保存.创建.更新和删除的对象. 基架指使用 MVC 提供的工具为每个模型对象的标准索引构建.创 ...

  5. Pro ASP.NET MVC –第二章 第一个MVC程序

    学习一个软件开发框架的最有效的方式就是了解并使用它.在本章,你将会创建一个简单基于ASP.NET MVC Framework的数据-实体应用程序.我们会该程序划分成若干小块,每次介绍一个部分,以便你能 ...

  6. ASP.NET + MVC5 入门完整教程八 -—-- 一个完整的应用程序(上)

    https://blog.csdn.net/qq_21419015/article/details/80509513 SportsStore 1.开始创建Visual Studio 解决方案和项目这里 ...

  7. ASP.NET + MVC5 入门完整教程三 (下) ---MVC 松耦合

    建立松耦合组件 MVC 模式最重要的特性之一视他支持关注分离,希望应用程序中的组件尽可能独立,只有很少的几个可控依赖项.在理想的情况下,每个组件都不了解其他组件,而只是通过抽象接口来处理应用程序的其他 ...

  8. ASP.NET MVC3入门教程之第一个WEB应用程序

    本文转载自:http://www.youarebug.com/forum.php?mod=viewthread&tid=91&extra=page%3D1 上一节,我们已经搭建好了AS ...

  9. 《精通ASP.NET MVC5》第7章 SportStore:一个真正的应用程序(1)

    7.1 开始 7.1.1 解决方案 个工程. 1. 一个域模块工程. 2.一个MVC4应用. 3.一个单元测试工程.         现在我们就创建一个名为 SportsStore 的空 soluti ...

随机推荐

  1. UVa 11174 (乘法逆元) Stand in a Line

    题意: 有n个人排队,要求每个人不能排在自己父亲的前面(如果有的话),求所有的排队方案数模1e9+7的值. 分析: <训练指南>上分析得挺清楚的,把公式贴一下吧: 设f(i)为以i为根节点 ...

  2. Oracle 课程六之hint

    课程目标 完成本课程的学习后,您应该能够: •什么是oracle hint •Hint的使用范围 •Hint 汇总 •演示常用的hint   Hint简介 Hint是oracle 提供的一种SQL语法 ...

  3. 顶 企业站常用css横向导航菜单

    <!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/T ...

  4. IPy的使用

    IPy - class and tools for handling of IPv4 and IPv6 addresses and networks. Website: https://github. ...

  5. POJ 1083 Moving Tables

    题意:一个建筑物里有400个房间,房间都在一层里,在一个走廊的两侧,如图,现在要搬n张桌子,告诉你每张桌子是从哪个屋搬到哪个屋,搬桌子的线路之间不可以有重叠,问最少搬几次. 解法:贪心.一开始觉得只要 ...

  6. [Papers]MHD, $\pi$, Lorentz space [Suzuki, DCDSA, 2011]

    $$\bex \sen{\pi}_{L^{s,\infty}(0,T;L^{q,\infty}(\bbR^3))} +\sen{{\bf b}}_{L^{\gamma,\infty}(0,T;L^{\ ...

  7. Android常用控件之FragmentTabHost的使用

    最近在学TabHost时发现TabActivity在API level 13以后不用了,所以就去寻找它的替换类,找到FragmentActivity,可以把每个Fragment作为子tab添加到Fra ...

  8. C# Read/Write another Process' Memory z

    http://www.codeproject.com/Articles/670373/Csharp-Read-Write-another-Process-Memory This article aim ...

  9. HDU 4035Maze(树状+概率dp,绝对经典)

    题意: 给你n个节点的树,从1节点开始走,到每个节点都有三种情况,被杀死回到1节点,找到隐藏的出口出去,沿着当前节点相邻的边走到下一个节点,给出每个节点三种情况发生的概率分别为ki,ei,1-ki-e ...

  10. DzzOffice管理员登陆方法和管理员应用介绍

    DzzOffice的管理方式类似于windows的管理方式,是直接在桌面中,通过管理员应用进行系统中的所有管理里工作. 1.访问http://www.domain.com (你站点的访问地址) 2.点 ...