c# - MVC 4 - 如何有条件地禁用此按钮?

标签 c# asp.net-mvc-4 razor

如果 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/

相关文章:

c# - 此代码的正确 IDisposable 实现

c# - DateTime.ToString 从所有格式到 dd/MM/YYYY?

.net - Windows 更新导致 MVC3 和 MVC4 停止工作

c# - 使用波浪号 (~) 存储路径并在 razor 中使用 html.raw 显示它

c# - C#中数组索引的类型?

c# - Form.Dispose() 是否调用 Dispose() 内部的控件?

javascript - 对象不支持 AngularJS 中的属性或方法 'success'

asp.net - 你调用的对象是空的。浏览器问题

c# - ViewStart 和 Layout - 有什么区别?

c# - ASP.NET MVC Razor 语法 : Is it an issue for razor to interpret @if(@Model