有条件地禁用此按钮

有条件地禁用此按钮

本文介绍了MVC 4-如何有条件地禁用此按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果Model.BicycleSellerListingId不大于0,我想有条件地禁用此按钮或将其隐藏.不确定该怎么做.

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>

推荐答案

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

这篇关于MVC 4-如何有条件地禁用此按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-24 06:50