【问题标题】:Enable and disable submit button depends the value of Viewbag启用和禁用提交按钮取决于 Viewbag 的值
【发布时间】:2020-11-17 16:44:42
【问题描述】:

我尝试启用或禁用提交按钮取决于 Viewbag.IsBtnEnabled 的值。如果 Viewbag.IsBtnEnabled = 'Y' 或 Viewbag.IsBtnEnabled=null 它应该被启用,否则提交 btn 应该被禁用。我的代码正在工作,除了空值。这是我的代码

<div class="center-block col-sm-6">
     <button type="submit" class="btn btn-primary form-control" id="btnSave"
             name="submit" @(ViewBag.IsBtnEnabled == "Y" ? "" : "disabled")>
         Save
     </button>
</div>

【问题讨论】:

  • 所以只检查它是否为空?
  • 我怎样才能在那里给出其他条件@(ViewBag.IsBtnEnabled == "Y" or null
  • 试试@(ViewBag.IsBtnEnabled == "Y" ? "" : (ViewBag.IsBtnEnabled == null ? "" : "disabled"))

标签: html asp.net-core model-view-controller


【解决方案1】:

如果 Viewbag.IsBtnEnabled = 'Y' 或 Viewbag.IsBtnEnabled=null 它应该被启用,否则提交 btn 应该被禁用。

要达到要求,可以试试下面的代码sn-p。

<div class="center-block col-sm-6">

    <button type="submit" class="btn btn-primary form-control" id="btnSave"
            name="submit" @((ViewBag.IsBtnEnabled == "Y" || ViewBag.IsBtnEnabled == null) ? "" : "disabled")>

        Save

    </button>

</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-08
    • 2019-03-19
    • 2012-12-19
    • 2014-11-28
    • 1970-01-01
    相关资源
    最近更新 更多