You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MVC提交按钮根据ViewBag.CurrentGroupName切换onclick方法

解决方案

直接在按钮的onclick属性中使用三元运算符,根据ViewBag.CurrentGroupName的值动态绑定对应的方法,修改后的完整代码如下:

<input type="button" 
       id="btnRemarksSubmitFLFTTX" 
       class="button submit" 
       value="@((ViewBag.CurrentGroupName == "O&M Fiber Lead") ? Html.Raw("Accept") : Html.Raw("Approve"))"
       onclick="@(ViewBag.CurrentGroupName == "O&M Fiber Lead" ? "return FiberLeadRejValidation_FTTX('Approve');" : "return SaveFiberInfofttx('Approve');")">

逻辑说明

  • 当ViewBag.CurrentGroupName等于"O&M Fiber Lead"时,按钮绑定FiberLeadRejValidation_FTTX('Approve')方法,同时显示文本为Accept
  • 当ViewBag.CurrentGroupName等于"O&M Fiber Engineer"时,按钮绑定SaveFiberInfofttx('Approve')方法,显示文本为Approve

内容的提问来源于stack exchange,提问作者Nadeem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 19:42:00