伙伴类的使用

Posted 从未太晚

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了伙伴类的使用相关的知识,希望对你有一定的参考价值。

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>

 

以上是关于伙伴类的使用的主要内容,如果未能解决你的问题,请参考以下文章

最全最详细publiccms其他常用代码片段(内容站点)

BootStrap实用代码片段(持续总结)

Jekyll 偏移代码片段高亮的初始行

推荐net开发cad入门阅读代码片段

使用片段从图库中选择图像

使用包含在 HTML 中的外部 CSS 类的 PdfSharp 从 HTML 片段创建 PDF