码迷,mamicode.com
首页 > Web开发 > 详细

MVC 小demo

时间:2018-02-19 19:20:12      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:bool   color   whether   label   sed   sage   ready   names   sel   

 

技术分享图片
.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>Were 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) { 
        @:Its great that youre coming.The drinks are already in the fridge.
        }
        else { 
            @:Sory to hear that you cant make it,but thanks for letting us know.
        }
    </div>
</body>
</html>
View→Home→Thanks.cshtml

 

MVC 小demo

标签:bool   color   whether   label   sed   sage   ready   names   sel   

原文地址:https://www.cnblogs.com/vichin/p/8454234.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!