[Display(Prompt MVC3

后端 未结 3 2075
南方客
南方客 2021-01-01 02:31

I am trying to setup my model so I can use the @Html.EditorFor(e => e.publicationTitle) and have it show a Watermark with a hint.

Currently I am do

3条回答
  •  无人及你
    2021-01-01 02:55

    In your controller you need to do the following

    [Display(Prompt="First Name Goes Here",Name="First Name")]
    [StringLength(100,ErrorMessage="First Name may not be longer than 100 characters")]
    public string AuthFirstName { get; set; }
    

    The Prompt="This is what will display" under display is the watermark that will be created.

    Then you will need to create the folder "EditorTemplates" under ~/Views/Shared the entire path will be ~/Views/Shared/EditorTemplates/

    Then create the file String.cshtml and place the following code in it

    @Html.TextBox("",ViewData.TemplateInfo.FormattedModelValue, new { @class="text-box single-line", placeholder = ViewData.ModelMetadata.Watermark })
    

    More detailed information can be found at the link posted by tugberk (SO question and SO answer).

提交回复
热议问题