1. <small id='NpF5o'></small><noframes id='NpF5o'>

      <bdo id='NpF5o'></bdo><ul id='NpF5o'></ul>

  2. <legend id='NpF5o'><style id='NpF5o'><dir id='NpF5o'><q id='NpF5o'></q></dir></style></legend>
    <tfoot id='NpF5o'></tfoot>

      <i id='NpF5o'><tr id='NpF5o'><dt id='NpF5o'><q id='NpF5o'><span id='NpF5o'><b id='NpF5o'><form id='NpF5o'><ins id='NpF5o'></ins><ul id='NpF5o'></ul><sub id='NpF5o'></sub></form><legend id='NpF5o'></legend><bdo id='NpF5o'><pre id='NpF5o'><center id='NpF5o'></center></pre></bdo></b><th id='NpF5o'></th></span></q></dt></tr></i><div id='NpF5o'><tfoot id='NpF5o'></tfoot><dl id='NpF5o'><fieldset id='NpF5o'></fieldset></dl></div>
    1. 我可以在部分类中定义属性,然后用另一个部分类中的属性标记它们吗?

      时间:2023-07-27

      <small id='IJPEZ'></small><noframes id='IJPEZ'>

            <tbody id='IJPEZ'></tbody>

            <tfoot id='IJPEZ'></tfoot>
          • <i id='IJPEZ'><tr id='IJPEZ'><dt id='IJPEZ'><q id='IJPEZ'><span id='IJPEZ'><b id='IJPEZ'><form id='IJPEZ'><ins id='IJPEZ'></ins><ul id='IJPEZ'></ul><sub id='IJPEZ'></sub></form><legend id='IJPEZ'></legend><bdo id='IJPEZ'><pre id='IJPEZ'><center id='IJPEZ'></center></pre></bdo></b><th id='IJPEZ'></th></span></q></dt></tr></i><div id='IJPEZ'><tfoot id='IJPEZ'></tfoot><dl id='IJPEZ'><fieldset id='IJPEZ'></fieldset></dl></div>

          • <legend id='IJPEZ'><style id='IJPEZ'><dir id='IJPEZ'><q id='IJPEZ'></q></dir></style></legend>
              • <bdo id='IJPEZ'></bdo><ul id='IJPEZ'></ul>

                本文介绍了我可以在部分类中定义属性,然后用另一个部分类中的属性标记它们吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                有没有办法生成这样的代码文件:

                Is there a way I can have a generated code file like so:

                public partial class A 
                {
                    public string a { get; set; }
                }
                

                然后在另一个文件中:

                public partial class A 
                {
                    [Attribute("etc")]
                    public string a { get; set; }
                }
                

                这样我就可以从数据库中生成一个类,然后使用一个非生成的文件来标记它?

                So that I can have a class generated from the database and then use a non-generated file to mark it up?

                推荐答案

                我在 Scott Guthrie 的一篇文章中看到过类似的事情(接近结尾)——不过,我自己没有尝试过.
                http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

                I've seen something like this done in an article by Scott Guthrie (near the end of it) - didn't try it myself, though.
                http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

                [MetadataType(typeof(Person_Validation))]
                public partial class Person
                {
                    // Partial class compiled with code produced by VS designer
                }
                
                [Bind(Exclude="ID")]
                public class Person_Validation
                {
                    [Required(ErrorMessage = "First Name Required")]
                    [StringLength(50, ErrorMessage = "Must be under 50 characters")]
                    public string FirstName { get; set; }
                
                    [Required(ErrorMessage = "Last Name Required")]
                    [StringLength(50, ErrorMessage = "Must be under 50 characters")]
                    public string LastName { get; set; }
                
                    [Required(ErrorMessage = "Age Required")]
                    [Range(0, 120, ErrorMessage = "Age must be between 0 and 120")]
                    public int Age { get; set; }
                
                    [Required(ErrorMessage = "Email Required")]
                    [Email(ErrorMessage = "Not a valid email")]
                    public string Email { get; set; }
                }
                

                这篇关于我可以在部分类中定义属性,然后用另一个部分类中的属性标记它们吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:P/Invoke [In, Out] 属性对于编组数组是可选的吗? 下一篇:为什么是“十进制"?不是有效的属性参数类型?

                相关文章

                <small id='H0t2L'></small><noframes id='H0t2L'>

                      <bdo id='H0t2L'></bdo><ul id='H0t2L'></ul>

                    <i id='H0t2L'><tr id='H0t2L'><dt id='H0t2L'><q id='H0t2L'><span id='H0t2L'><b id='H0t2L'><form id='H0t2L'><ins id='H0t2L'></ins><ul id='H0t2L'></ul><sub id='H0t2L'></sub></form><legend id='H0t2L'></legend><bdo id='H0t2L'><pre id='H0t2L'><center id='H0t2L'></center></pre></bdo></b><th id='H0t2L'></th></span></q></dt></tr></i><div id='H0t2L'><tfoot id='H0t2L'></tfoot><dl id='H0t2L'><fieldset id='H0t2L'></fieldset></dl></div>
                  1. <legend id='H0t2L'><style id='H0t2L'><dir id='H0t2L'><q id='H0t2L'></q></dir></style></legend>
                    <tfoot id='H0t2L'></tfoot>