0

I want to hide a button based on a value in my model which I am passing to the page.

    @model Indigo.Contracts.DataContracts.JobDetailDto

    @{
        Layout = "~/Views/Shared/_Layout.cshtml";
    }

    <script>
        $(document).ready(function () {
            if(@Model.StatusNameInternal === "Completed")
            {
                $('#cancelButton').prop("hidden", true);
            }
            });
    </script>

<table>
    <tr>
        <td>&nbsp;</td>
        <td><input type="submit" id="cancelButton" value="Cancel" /></td>
        <td><input type="submit" id="restartButton" value="Restart" /></td>
        <td><input type="submit" id="finalizeButton" value="Finalize" /></td>
    </tr>
</table>

What I would like to do is, when my document is ready, check if the StatusNameInternal = "Completed", then hide the cancelButton.

2 Answers 2

2

You're close. Since @Model.StatusNameInternal resolves to a string, you need to quote that value in your JavaScript:

if ('@Model.StatusNameInternal' === 'Completed') {

Also, I'm not sure that .prop('hidden', true) will do what you want. I think you probably want .hide() or .css('visibility', 'hidden').

Sign up to request clarification or add additional context in comments.

1 Comment

You were correct, it seems that I was close. And the 'hidden' doesn't work, so I'm using the .hide() now.
0

Try this:

 <script>
            $(document).ready(function () {
                if(@Model.StatusNameInternal === "Completed")
                {
                    $('#cancelButton').hide();
                }
                });
        </script>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.