8

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>
4

1 回答 1

35
<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>

或者

@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>
}

或者

<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>
于 2013-03-06T12:55:14.227 回答