I used forests to create views and controllers for me, and I use the EF code syntax.
I understand that T4 templates are responsible for implementing attribute values ββin the generated HTML / view code, but I donβt see the default forest template available with the VS 2015 community edition for anything for placeholder text.
In my understanding, when decorating a model property, the [Display(Prompt="some placeholder text")] attribute causes some placeholder text appear as a placeholder for the input text field in the create / edit views.
But, to my horror, this does not happen.
Is there any other attribute? or something else i need to do? or is it because i used scaffolding to create views? or does the default T4 template not do its job very well?
My code for the model class is as follows:
public class Status { public int ID { get; set; } [Required(ErrorMessage ="Status Name is needed!")] [Display(Name ="Status Name",Prompt ="Type something here!")] public string StatusName { get; set; } [Required] public string Description { get; set; } }
The following is the code for the generated view:
@model LunchFeedback.Models.Status @{ ViewBag.Title = "Create"; } <h2>Create</h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>Status</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.StatusName, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.StatusName, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.StatusName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Create" class="btn btn-default" /> </div> </div> </div> } <div> @Html.ActionLink("Back to List", "Index") </div> @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
Edit:
I am well aware that directly editing a view file and adding a placeholder can do the job.
@Html.EditorFor(model => model.StatusName, new { htmlAttributes = new { @class = "form-control", placeholder = "Type something here!" } })
But I want to control all the things from the model and want to use scaffolding. It is even preferable to edit / customize the T4 template for this.