0

How to add placeholder to c# code ? I want to display DateTime.Now in my form.

<div class="col-md-10">
  @Html.EditorFor(model => model.Date,  new { htmlAttributes = new { @class = "form-control"  } })
  @Html.ValidationMessageFor(model => model.Date, "", new { @class = "text-danger" })
</div>
Sami Kuhmonen
  • 30,146
  • 9
  • 61
  • 74

2 Answers2

2

Have your tried -

  @Html.EditorFor(model => model.Date, new { placeholder =  DateTime.Now.ToString("MM/dd/yyyy")})
KnightFox
  • 3,132
  • 4
  • 20
  • 35
0
/** Here is how I did it in my code. I had a richtexBox5 that I needed to add QTY placeholder. So what did was, inside public form i did the following */
  public Form1()
        {
            InitializeComponent();

         richTextBox5.Text = "QTY";// set text you want to show

         if (richTextBox5.Text == "QTY")
            {
             richTextBox5.ForeColor = Color.LightGray;// set color
           }
        }

/**now make this function which will listen to mouse click  in wherever part you want*/
 private void richTextBox5_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {           
            if(richTextBox5.Text=="QTY") // check what is in that textbox
            {
                richTextBox5.Text = "";// set it to null 
                richTextBox5.ForeColor = Color.Black;// change color
            }      
        }
kupaff
  • 329
  • 4
  • 5