user2739418
user2739418

Reputation: 1631

Placeholder in MVC 4 model or view

I am trying to set place holder to textbox or multi line text box in MVC 4. So far it is not working.

[Display(Name = "Location", Prompt = "Enter info related to Location")]
public string LocationDesc { get; set; }

And the View as below

@Html.EditorFor(model => model.LocationDesc , new { placeholder = "Enter info related to Location" })

Place holder just need to show some information and I am happy to display it anywhere (View or model)

We are using MVC4.

Cheers

Upvotes: 0

Views: 445

Answers (1)

Kartikeya Khosla
Kartikeya Khosla

Reputation: 18893

You cannot use Placeholder attribute on @Html.EditorFor() in asp.net mvc,there are two solutions for your problem :

1.) You can make a custom attribute for @Html.EditorFor() a great article on this is there on stackoverflow link :- Html5 Placeholders with .NET MVC 3 Razor EditorFor extension? and you can visit this link also http://aspadvice.com/blogs/kiran/archive/2009/11/29/Adding-html-attributes-support-for-Templates-2D00-ASP.Net-MVC-2.0-Beta_2D00_1.aspx

2.) Instead of @Html.EditorFor() you can use @Html.TextAreaFor()

Upvotes: 1

Related Questions