2013-02-22 60 views
6

我在我的.cshtml下面的代碼:MVC助手文本區 - 佔位符不顯示

@Html.TextArea("txtComments", new { style = "width: 450px;", placeholder = "Enter Comments here" }) 

但佔位符不顯示在所有。我錯過了什麼嗎?

來源:

<textarea cols="20" id="txtComments" name="txtComments" placeholder="Enter Comments here" rows="2" style="width: 450px;"> 
</textarea> 
+0

正如我所說的,代碼正在工作,它顯示你的佔位符。你確定這不是你的CSS的問題嗎? – 2013-02-22 09:58:37

+0

Dono whatz造成的。我試圖在沒有Css的空白頁面也仍然不會來..奇怪 – user2067567 2013-02-22 10:02:09

+0

你目前使用什麼瀏覽器? – 2013-02-22 10:03:04

回答

8

把一個@的風格和placerholder之前,像這樣,甚至把htmlAttributes:之前。

@Html.TextArea("txtComments", htmlAttributes: new { @style = "width: 450px;", @placeholder = "Enter Comments here" }) 

這是確切輸出我得到:

<textarea cols="20" id="txtComments" name="txtComments" placeholder="Enter Comments here" rows="2" style="width: 450px;"></textarea> 

如果顯示的佔位符,但它仍然沒有顯示,請確保您使用的是跟上時代的網頁瀏覽器,你可以找到支持的瀏覽器的列表,在這裏:http://caniuse.com/input-placeholder

< IE10 does not support it. 

如果確實需要在這些瀏覽器的支持,也許這解決方案將幫助你:http://webdesignerwall.com/tutorials/cross-browser-html5-placeholder-text

+0

沒有。仍然無法正常工作 – user2067567 2013-02-22 09:54:49

+0

然後,其他問題就是代碼爲我工作的問題。你可以發佈你的'@ Html.TextArea'行生成的'html'嗎?檢查佔位符不在那裏,但你的CSS已經停止它顯示。 – 2013-02-22 09:56:01

+0

same.see我更新的問題。 – user2067567 2013-02-22 09:58:16