Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placeholder in @Html.EditorFor(model => model.Name) in MVC 5

I used [prompt("name")] in Controller and

@Html.EditorFor(model => model.Email,
new {placeholder=ViewData.ModelMetadata.Watermark})`

in view but nothing showed I also used help of Html5 Placeholders with .NET MVC 3 Razor EditorFor extension? but nothing happened I need Placeholder for @EditorFor not for Textbox Any Help Appreciated

like image 858
Suyash Kumar Singh Avatar asked Oct 31 '25 20:10

Suyash Kumar Singh


2 Answers

You can write HTML attributes into Html.EditorFor using the following syntax. Make sure you use @ before class and placeholder so that the renderer knows this is HTML markup.

@Html.EditorFor(model => model.Email, new { 
    htmlAttributes = new { 
        @class = "form-control", 
        @placeholder = "Email Address"
    }
})
like image 126
user7900201 Avatar answered Nov 02 '25 12:11

user7900201


EditorFor doesn't accept HtmlAttribut argument you have to use TextBoxFor instead of it ;) try this:

@Html.TextBoxFor(model => model.Email, new  {placeholder=ViewData.ModelMetadata.Watermark})`
like image 34
TRIKI Khaled Avatar answered Nov 02 '25 12:11

TRIKI Khaled