{"id":1060,"date":"2022-04-09T17:15:30","date_gmt":"2022-04-09T09:15:30","guid":{"rendered":"http:\/\/www.wayln.com\/?p=1060"},"modified":"2022-04-09T17:55:55","modified_gmt":"2022-04-09T09:55:55","slug":"data-annotaionsmode-%e9%aa%8c%e8%af%81%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wayln.com\/?p=1060","title":{"rendered":"Data Annotaions(Model \u9a8c\u8bc1\uff09"},"content":{"rendered":"<div id=\"toc_container\" class=\"toc_transparent no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#Model\"><span class=\"toc_number toc_depth_1\">1<\/span> Model\u9a8c\u8bc1<\/a><ul><li><a href=\"#i\"><span class=\"toc_number toc_depth_2\">1.1<\/span> \u9632\u6b62\u8de8\u7ad9\u8bf7\u6c42\u4f2a\u9020\u9a8c\u8bc1<\/a><\/li><\/ul><\/li><li><a href=\"#i-2\"><span class=\"toc_number toc_depth_1\">2<\/span> \u754c\u9762\u663e\u793a\u9a8c\u8bc1\u95ee\u9898<\/a><\/li><\/ul><\/div>\n<h1><span id=\"Model\">Model\u9a8c\u8bc1<\/span><\/h1>\n<pre><code class=\"language-CSharp line-numbers\">using System;\nusing System.Collections.Generic;\nusing System.ComponentModel.DataAnnotations;\nusing System.Linq;\nusing System.Threading.Tasks;\n\nnamespace WebApplication3.Models\n{\n    public class Movie\n    {\n        public int Id { get; set; }\n\n        [Required]\n        [StringLength(100)]\n        public string Title { get; set; }\n\n        [DataType(DataType.Date)]\n        public DateTime ReleaseDate { get; set; }\n\n        [Required]\n        [StringLength(1000)]\n        public string Description { get; set; }\n\n        [Range(0,999.99)]\n        public decimal  Price { get; set; }\n\n\n    }\n}\n\n<\/code><\/pre>\n<ul>\n<li>[CreditCard]<\/li>\n<li>[Compare]<\/li>\n<li>[EmailAddress]<\/li>\n<li>[Phone]<\/li>\n<li>[Range]<\/li>\n<li>[RegularExpression]<\/li>\n<li>[Required]<\/li>\n<li>[StringLength]<\/li>\n<li>[Url]<\/li>\n<li>[Display]<\/li>\n<li>[DataType(DateType=)]<\/li>\n<\/ul>\n<h2><span id=\"i\">\u9632\u6b62\u8de8\u7ad9\u8bf7\u6c42\u4f2a\u9020\u9a8c\u8bc1<\/span><\/h2>\n<p>\u4f7f\u7528[ValidateAntiForgeryToken]<\/p>\n<pre><code class=\"language-CSharp line-numbers\">  public class HomeController : Controller\n    {\n        [HttpPost]\n        [ValidateAntiForgeryToken]\n        public IActionResult Index(int id)\n        {\n\n            StudentsViewModel svm = new StudentsViewModel();\n            var s= svm.GetStudentById(id);\n            if(s==null)\n}\n}\n<\/code><\/pre>\n<h1><span id=\"i-2\">\u754c\u9762\u663e\u793a\u9a8c\u8bc1\u95ee\u9898<\/span><\/h1>\n<p>\u663e\u793a\u5355\u4e2a\u9519\u8bef\u4fe1\u606f<\/p>\n<pre><code class=\"language-HTML line-numbers\">  &lt;span asp-validation-for=\"@Model.FirstName\"&gt;&lt;\/span&gt;\n<\/code><\/pre>\n<p>\u9a8c\u8bc1\u4fe1\u606f\u63d0\u793a\u6c47\u603b<\/p>\n<pre><code class=\"language-HTML line-numbers\">  &lt;div asp-validation-summary=\"All\"&gt;&lt;\/div&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Contents1 Model\u9a8c\u8bc11.1 \u9632\u6b62\u8de8\u7ad9\u8bf7\u6c42\u4f2a\u9020\u9a8c\u8bc12 \u754c\u9762\u663e\u793a\u9a8c\u8bc1\u95ee\u9898 Model\u9a8c\u8bc1 using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44,4,2],"tags":[],"class_list":["post-1060","post","type-post","status-publish","format-standard","hentry","category-asp-net-core","category-c","category-2"],"_links":{"self":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/1060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1060"}],"version-history":[{"count":7,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/1060\/revisions"}],"predecessor-version":[{"id":1069,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/1060\/revisions\/1069"}],"wp:attachment":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}