码迷,mamicode.com
首页 > 其他好文 > 详细

伙伴类的使用

时间:2016-09-12 20:40:05      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace MvcApp.Models
{
    public class UserInfoValidate
    {
        [Required(ErrorMessage="编号不能为空")]
        public int ID{ get; set; }
        [Required(ErrorMessage="用户名不能为空")]
        public string UserName { get; set; }
    }
    [MetadataType(typeof(UserInfoValidate))]
    public partial class UserInfo
    {

    }
}
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcApp.Models.UserInfo>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CreateUser</title>
    <style type="text/css">
    .txt{color:Red}
    
    </style>
</head>
<body>
<%Html.EnableClientValidation(); %>
    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
    <% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary(true) %>

        <fieldset>
            <legend>Fields</legend>
            
            <div class="editor-label">
                <%: Html.LabelFor(model => model.ID) %>
            </div>
            <div class="editor-field">
                <%: Html.TextBoxFor(model => model.ID) %>
                <%: Html.ValidationMessageFor(model => model.ID, "", new {@class="txt" })%>
            </div>
            
            <div class="editor-label">
                <%: Html.LabelFor(model => model.UserName) %>
            </div>
            <div class="editor-field">
                <%: Html.TextBoxFor(model => model.UserName) %>
                <%: Html.ValidationMessageFor(model => model.UserName) %>
            </div>
            
            <div class="editor-label">
                <%: Html.LabelFor(model => model.UserPass) %>
            </div>
            <div class="editor-field">
                <%: Html.TextBoxFor(model => model.UserPass) %>
                <%: Html.ValidationMessageFor(model => model.UserPass) %>
            </div>
            
            <div class="editor-label">
                <%: Html.LabelFor(model => model.RegTime) %>
            </div>
            <div class="editor-field">
                <%: Html.TextBoxFor(model => model.RegTime) %>
                <%: Html.ValidationMessageFor(model => model.RegTime) %>
            </div>
            
            <div class="editor-label">
                <%: Html.LabelFor(model => model.Email) %>
            </div>
            <div class="editor-field">
                <%: Html.TextBoxFor(model => model.Email) %>
                <%: Html.ValidationMessageFor(model => model.Email) %>
            </div>
            
            <p>
                <input type="submit" value="Create" />
            </p>
        </fieldset>

    <% } %>

    <div>
        <%: Html.ActionLink("Back to List", "Index") %>
    </div>

</body>
</html>

 

伙伴类的使用

标签:

原文地址:http://www.cnblogs.com/kongsq/p/5865982.html

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