首页 > 代码库 > 伙伴类的使用
伙伴类的使用
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=http://www.mamicode.com/"../../Scripts/MicrosoftAjax.js" type="text/javascript"></script> <script src=http://www.mamicode.com/"../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script> <script src=http://www.mamicode.com/"../../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=http://www.mamicode.com/"Create" /> </p> </fieldset> <% } %> <div> <%: Html.ActionLink("Back to List", "Index") %> </div></body></html>
伙伴类的使用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。