MVC 4 Custom template for bool (razor)

后端 未结 4 1554
夕颜
夕颜 2021-02-07 09:37

I am using the twitter bootstrap framework, so to get the EditorFor and DisplayFor methods to output what I need, I created custom templates for each of the types like string, t

4条回答
  •  不知归路
    2021-02-07 10:16

    You have to initialize your RememberMe bool value inside the constructor as shown below.

    Remember that using uninitialized variables in C# is not allowed.

    using System.ComponentModel; 
    
    public class ClassName
     {    
       public ClassName ()
            {
                RememberMe = false;
            }
    
       [DefaultValue(false)]
       [Display(Name = "Remember me?")]
       public bool RememberMe { get; set; }
     }
    

    For more infromation check Default Values Table

    I hope this will help to you.

提交回复
热议问题