2011-10-19 91 views
1

下面這段代碼正常工作:MVC 3 Razor視圖引擎格式

<span class="dysiChannelSubscription"> 
@if (Model.ChannelName == "ninacopes") 
{ 
    <iframe allowtransparency="true" frameborder="0" scrolling="no" style="width:200px; height:20px;" 
     src="//platform.twitter.com/widgets/follow_button.html?show_count=false&[email protected]"> 
    </iframe> 
} 
</span> 

但是,如果我改變了,如果到:

@if (Model.ChannelType == Fluent.Data.Enums.ChannelTypeEnum.Twitter) 

它不提供任何更長的時間。 這是局部視圖。

jQuery的收益率:

語法錯誤
<!DOCTYPE html>

我不知道爲什麼。 Model.ChannelType是這種類型的,並且我純粹從intellisense中獲得了twitter值,這讓我想知道爲什麼這會打破。

回答

2

如果雙方都是字符串,那麼你可以嘗試下面的.ToString()。

@if (Model.ChannelType == Fluent.Data.Enums.ChannelTypeEnum.Twitter.ToString()) 

如果兩邊都是整數,那麼你可以嘗試

@if (Model.ChannelType == (int)Fluent.Data.Enums.ChannelTypeEnum.Twitter) 
0

你想比較模型的類型嗎?如果不是這樣的話:TypeOf(Model.ChannelType)

+0

什麼? 'ChannelType'是一個類型爲'ChannelTypeEnum'的枚舉 – bevacqua