Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding disabled attribute to a button using Razor [duplicate]

I have a bool in my ViewModel called DisableNextButton and I would like to use it to disable a button in my view. I should add that this button lives inside an if statement.

Ultimately, I'm trying to add the disabled attribute when DisableNextButton is true.

Here's my unsuccessful implementation:

@if(true)
{
    <button type="button" @{ if (Model.DisableNextButton) { <text>disabled="disabled"</text> } } >Next</button>
}

I should note that this gives me a functioning enabled button.

like image 757
lobsterhat Avatar asked Sep 24 '26 21:09

lobsterhat


1 Answers

Translated from this post:

<input type="button" value="Next" 
    @{
        if(Model.DisableNextButton)
        {
            @:disabled="disabled"
        }
    }
/>

Basically, the <text> tag is unnecessary, as this is not text, it's an HTML attribute.

like image 80
Codeman Avatar answered Sep 27 '26 10:09

Codeman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!