[Display(Prompt MVC3

后端 未结 3 2052
南方客
南方客 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:50

    The placeholder attribute is not supported in earlier versions of IE, so for the Display[(Promt="...")] to work fine I recommend to use (along with the String template as Samack described) any jQuery watermark plugin (I used the google one) then add this to the Document.Ready function:

    $(document).ready(function(){
        $(':text').watermark({ textAttr: 'placeholder' });
    })
    
    0 讨论(0)
  • 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).

    0 讨论(0)
  • 2021-01-01 03:01

    This will not work with IE unfortunately. At least IE9 and earlier. I spent couple hours pulling my hair as to why this helped others and doesn't work here. Apparently IE won't show prompts. Hope IE10 will address the issue.

    0 讨论(0)
提交回复
热议问题