如果 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))
{
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>
关于c# - MVC 4 - 如何有条件地禁用此按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15247832/