How can I use placeholder attribute with Html.EditorFor?

后端 未结 5 1265
迷失自我
迷失自我 2021-02-06 22:14

I want to use the placeholder attribute in the Html.EditorFor so I did just like in the first answer: Html5 Placeholders with .NET MVC 3 Razor EditorFor extension?

But i

5条回答
  •  有刺的猬
    2021-02-06 22:28

    When using TextBoxFor or TextAreaFor rather than EditorFor, use only the inner key-value pair from @Medo's answer, since the method directly expects an htmlAttributes object:

    @Html.TextBoxFor(m => m.variable, new { placeholder = "Your Placeholder Text" })
    

    (I realize this is tangential to the original question, but having this here would have helped me when I landed on this page earlier, looking for an answer to how to add placeholder text to an Html.TextAreaFor!)

提交回复
热议问题