DavidB
DavidB

Reputation: 2596

Incorrect Razor ternary syntax

Im copied this ternary from another SO post:

  <td><input type="button" value="Delete" class="DeleteButton" id="@("D" + param.QueueId)" @{ if(param.StatusId != 1) { @:disabled="disabled" } } /></td>

But it is causing compilation errors.

End of file or an unexpected character was reached before the input tag could be parsed.

Upvotes: 0

Views: 358

Answers (2)

haim770
haim770

Reputation: 49095

The @: is causing the problem, since it doesn't know where the output ends and Razor starts, try to replace it with:

<text>disabled="disabled"</text>

Upvotes: 2

Łukasz W.
Łukasz W.

Reputation: 9755

Try to change:

@{ if(param.StatusId != 1) { @:disabled="disabled" } }

to:

@(param.StatusId != 1 ? "disabled='disabled'" : string.Empty)

Upvotes: 2

Related Questions