[英]Check if a view model property is a string
我在視圖中具有以下foreach,我希望它遍歷視圖模型中的屬性,並為每個字符串屬性顯示一個文本框。
foreach (var property in ViewData.ModelMetadata.Properties)
{
if(property.GetType() == "string")
{
<div class="watermark">
<label>Friend's email address</label>
<br>
@Html.Editor(property.PropertyName)
</div>
}
}
理想情況下,property.GetType()==“ string”將返回true或false,但這不是事實,因為.GetType始終返回System.Type(我相信)。
嘗試這個
if(property.GetType() == typeof(string))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.