How do I add placeholder text from the model into a MVC view?

后端 未结 9 1071
余生分开走
余生分开走 2021-02-05 12:43

I have a model:

[DataType(DataType.EmailAddress)]
[DisplayFormat(ConvertEmptyStringToNull = true)]
[Display(Prompt = \"Email Address\")]
public string Email { ge         


        
9条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 13:24

    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) 
    

提交回复
热议问题