zoukankan      html  css  js  c++  java
  • MVC 校验

    @model MVCFirst.Models.Person
    @{
        Layout = null;
    }


    <!DOCTYPE html>


    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Add</title>
        <script src="~/Scripts/jquery-1.10.2.min.js"></script>
        <script src="~/Scripts/jquery.validate.min.js"></script>
        <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
    </head>
    <body>
        <div> 
            @using (Html.BeginForm("Add", "Person", FormMethod.Post))
            {
                @Html.TextBoxFor(p => p.Id)
                @Html.ValidationMessageFor(p=>p.Id)
                @Html.TextBoxFor(p=>p.Name)
                <input type="submit" name="name" value="Add" />
            }
        </div>
    </body>

    </html>


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


    namespace MVCFirst.Models
    {
        public class Person
        {
            [Required(ErrorMessage ="编号不能为空")]
            [Range(10,100,ErrorMessage ="必须在10到100之间")]

            public int Id { get; set; }
            public string Name { get; set; }
        }




    }

  • 相关阅读:
    洛谷P3796
    cf1291c-Mind Control
    莫比乌斯函数
    C. Mixing Water(三分)
    E. Modular Stability(思维构造)
    【美团杯2020】平行四边形
    原根定义
    E. Are You Fired?(思维)
    102606C. Coronavirus Battle time limit per test4 seconds(三维拓扑序)
    E
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434747.html
Copyright © 2011-2022 走看看