Reputation: 3813
I have the following code in my .cshtml:
@Html.TextArea("txtComments", new { style = "width: 450px;", placeholder = "Enter Comments here" })
But the placeholder is not displaying at all. Am I missing something?
Source:
<textarea cols="20" id="txtComments" name="txtComments" placeholder="Enter Comments here" rows="2" style="width: 450px;">
</textarea>
Upvotes: 10
Views: 14849
Reputation: 1
This one is working for me (asp.net v4.6.2 mvc5) :
@Html.TextAreaFor(model => model.MyMessageForm.MessageText, new { placeholder = "Your msg here...", @class = "form-control" } )
Upvotes: 0
Reputation: 7475
Put an @ before the style and placerholder, like so, maybe even put htmlAttributes:
before it.
@Html.TextArea("txtComments", htmlAttributes: new { @style = "width: 450px;", @placeholder = "Enter Comments here" })
And this is the exact output I get:
<textarea cols="20" id="txtComments" name="txtComments" placeholder="Enter Comments here" rows="2" style="width: 450px;"></textarea>
If this shows a placeholder but it still isn't showing, make sure you're using an up-to-date web browser, you can find a list of the supported browsers here: http://caniuse.com/input-placeholder
< IE10 does not support it.
If you do need support in those browsers, maybe this solution will help you: http://webdesignerwall.com/tutorials/cross-browser-html5-placeholder-text
Upvotes: 15