bevacqua
bevacqua

Reputation: 48566

MVC 3 Razor View Engine Formatting

The following piece of code works correctly:

<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>

However, if I change the if to:

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

It doesn't render any longer. This is in a partial view.

jQuery yields:

syntax error
<!DOCTYPE html>

I have no clue why. Model.ChannelType is of that type, and I get the twitter value purely from intellisense, which makes me wonder why this breaks at all.

Upvotes: 1

Views: 218

Answers (2)

Rajkumar
Rajkumar

Reputation: 153

If both sides are strings then you can try .ToString() like below.

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

If both Sides are Integer then you can try

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

Upvotes: 2

Jesse
Jesse

Reputation: 8393

Are you trying to compare the type of the model? Should it not then be something like: TypeOf(Model.ChannelType) ?

Upvotes: 0

Related Questions