Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Helper TextArea - Placeholder not displaying

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>
like image 714
user2067567 Avatar asked Feb 22 '13 09:02

user2067567


1 Answers

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

like image 61
Adam K Dean Avatar answered Oct 23 '22 03:10

Adam K Dean