Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 4 - How to conditionally disable this button?

I would like to conditionally disable this button, or hide it, if Model.BicycleSellerListingId is not greater than 0. Not sure how to do it.

<div style="position:absolute; left:300px; top:633px;">
    @using (Html.BeginForm("Delete", null, new { id = Model.BicycleSellerListingId }, FormMethod.Post))
    {
       <button type="submit">Delete Listing</button>
    }
</div>
like image 778
Hosea146 Avatar asked Mar 06 '13 12:03

Hosea146


1 Answers

<div style="position:absolute; left:300px; top:633px;">
@using (Html.BeginForm("Delete", null, new { id = Model.BicycleSellerListingId }, FormMethod.Post))
{
   if(Model.BicycleSellerListingId < 0){
       <button type="submit">Delete Listing</button>
   }
}
</div>

OR

@if(Model.BicycleSellerListingId < 0){
    <div style="position:absolute; left:300px; top:633px;">
    @using (Html.BeginForm("Delete", null, new { id = Model.BicycleSellerListingId }, FormMethod.Post))
    {
       <button type="submit">Delete Listing</button>
    }
    </div>
}

OR

<div style="position:absolute; left:300px; top:633px;">
@using (Html.BeginForm("Delete", null, new { id = Model.BicycleSellerListingId }, FormMethod.Post))
{
    <button type="submit"  @((Model.BicycleSellerListingId < 0) ? "disabled" : "")>Delete Listing</button>
}
</div>
like image 171
AliRıza Adıyahşi Avatar answered Sep 21 '22 23:09

AliRıza Adıyahşi