I have a model:
[DataType(DataType.EmailAddress)]
[DisplayFormat(ConvertEmptyStringToNull = true)]
[Display(Prompt = \"Email Address\")]
public string Email { ge
In your controller method that renders view say
ViewData["Name"] = "blabbity blah";
then
@Html.TextBoxFor(u => u.Company, new { @placeholder = @ViewData["Name"] })
Actually better yet you can do this.
public ActionResult Index()
{
NewLogin n = new ClassModel().PopModel();
n.Company = "fsdfsdf";
return View(n);
}
@Html.TextBoxFor(u => u.Company, new { @placeholder = Model.Company })
@Html.TextBoxFor(m => m.Email, new { @class = "form-control" , @placeholder = "Username" })
A little late, but if someone is still looking for it...
@Html.EditorFor(model => model.Email,
new { htmlAttributes = new { @class = "form-control input-md",
@placeholder = "Whatever you want as a placeholder" } })
It's perfect and clean!
Check out this answers to this question, which has been answered aleady (a few times).
@Html.EditorFor
uses templates, and so the approach to this problem is using a customised template.
This solved my issue:
@Html.EditorFor(model => model.Email, new { htmlAttributes =
new { @class = "form-control input-sm",
placeholder = @Html.DisplayNameFor(m=>m.Email) } })
The code that did it was
placeholder = @Html.DisplayNameFor(m=>m.Email)
you can use it as follows for the date which will also give you a "datetime" picker.
[DisplayFormat(DataFormatString ="{0:yyyy-MM-dd}",ApplyFormatInEditMode =true)]