Sunday, June 5, 2016

PlaceHolder in ASP.NET MVC 5.2.3


1) With use of MVC Data Annotations:
     Model:
    [Required]
    [Display(Prompt = "Enter Your First Name")]
    public string FirstName { get; set; }

    Razor Syntax:
    @Html.TextBoxFor(m => m.FirstName, new { placeholder = @Html.DisplayNameFor(n => n.UserName)})
 
 
2) With use of MVC Data Annotations But with DisplayName:
 
  Model:
   [Required]
   [DisplayName("Enter Your First Name")]
   public string FirstName { get; set; }  
 
  Razor Syntax: 
     
@Html.TextBoxFor(m => m.FirstName, new { placeholder = @Html.DisplayNameFor(n => n.UserName)})
 
 
3) Without use of MVC Data Annotation (recommended):
 
 @Html.TextBoxFor(m => m.FirstName, new { @placeholder = "Enter Your First Name")