2013-03-06 5 views
5

Ich möchte diese Schaltfläche bedingt deaktivieren oder ausblenden, wenn Model.BicycleSellerListingId nicht größer als 0 ist. Nicht sicher, wie es geht.MVC 4 - Wie Sie diese Schaltfläche bedingt deaktivieren?

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

Antwort

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

ODER

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

ODER

<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> 
+1

Sehr schön und sehr einfach. Einfacher als ich dachte. – Hosea146

Verwandte Themen