0

I have some code like:

<table class="invisibleforprint">
    <thead>
        <tr class="mainheader">
            <th>@Html.ActionLink("Invoice Number", "Index", new { sortOrder= ViewBag.NumberSortParm })</th>
        </tr>
    </thead>
    <tbody>
    @foreach (var item in Model) {
        <tr>
            <td class="invoiceActions">
                <input type="button" class="btnresetinvoice button" value="Reset" data-invoiceid="@item.InvoiceId" />
            </td>
        </tr>
    }</tbody>
</table>

Which compiled fine. I went and added an if statement in the input:

<table class="invisibleforprint">
    <thead>
        <tr class="mainheader">
            <th>@Html.ActionLink("Invoice Number", "Index", new { sortOrder= ViewBag.NumberSortParm })</th>
        </tr>
    </thead>
    <tbody>
    @foreach (var item in Model) {
        <tr>
            <td class="invoiceActions">
                <input type="button" class="btnresetinvoice button" value="Reset" data-invoiceid="@item.InvoiceId" @{ if(item.PMApproved != true) { @:disabled="disabled" } } />
            </td>
        </tr>
    }</tbody>
</table>

It's giving the error '} expected'

Say what? I've added an equal amount of opening closing brackets.

Anyone know what I've done wrong?

AnonyMouse
  • 18,108
  • 26
  • 79
  • 131

4 Answers4

1
<input type="button" class="btnresetinvoice button" value="Reset" data-invoiceid="@item.InvoiceId" @(item.PMApproved != true ? "disabled='disabled'" : "" ) />
superlogical
  • 14,332
  • 9
  • 66
  • 76
1
<input type="button" value="Reset" data-invoiceid="@item.InvoiceId" @(item.PMApproved ? "disabled=\"disabled\"" : null) />

Or you can use @if with <text> tag:

<input type="button" value="Reset" data-invoiceid="@item.InvoiceId" @if(item.PMApproved) { <text>disabled="disabled"</text>} />
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
0

Instead of using curly braces around your if statement, you should be using normal brackets.

i.e.:

@( if(item.PMApproved != true) { @:disabled="disabled" } )

Can you give that a try?

Steve Hobbs
  • 3,296
  • 1
  • 22
  • 21
0

You could perform the following pornography (but please don't):

<input type="button" class="btnresetinvoice button" value="Reset" data-invoiceid="@item.InvoiceId" @Html.Raw(item.PMApproved ? "disabled=\"disabled\"" : "") />

or use helpers as I suggested you:

@Html.ApproveButton(item)
Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928