html - 单击任何按钮后如何禁用/隐藏所有按钮(cshtml)
问题描述
一旦用户单击任何按钮,我想知道如何禁用/隐藏所有按钮。我只能使用 c# 或 html。我在 Javascript 中找到了解决方案,但我无法使用它。(由于空间不足,我没有上传我的 razor c# 代码)
我正在创建一个程序,允许用户投票给任何一个候选人。一旦用户点击并选择了一个候选人,投票结果将被显示,用户不应再次投票。
<!DOCTYPE html>
<html>
<head>
<title>Elections</title>
</head>
<body>
<form id="form1" method="post">
<div>
<table>
<tr>
<td>Harry</td>
<td><input id="Harry" name="submit" type="submit" value="Vote Harry" /></td>
</tr>
<tr>
<td>John</td>
<td><input id="John" name="submit" type="submit" value="Vote John" /></td>
</tr>
<tr>
<td>Bryan</td>
<td><input id="Bryan" name="submit" type="submit" value="Vote Bryan" /></td>
</tr>
<tr>
<td>Jack</td>
<td><input id="Jack" name="submit" type="submit" value="Vote Jack" /></td>
</tr>
</table>
</div>
<div>
@if (result != "")
{
<p>@result</p>
}
<!--Ensure that user has voted before showing the vote results-->
@if (voteCheck == true)
{
<p>Total Votes: @Session["totalVotes"]</p> <!--using session allows values to be kept even after button click-->
<p> Harry: @Session["Harry"]</p>
<p> John: @Session["John"]</p>
<p> Bryan: @Session["Bryan"]</p>
<p> Jack: @Session["Jack"]</p>
}
</div>
</form>
</body>
</html>
解决方案
您需要表单的操作属性action="youraction/controller here"
并在您的操作中编写一些显示值的 C# 代码返回列表(“无”或“”)并在 cshtml 中添加style="display:@display"
<input id="Harry" name="submit" type="submit" style="display:@display" value="Vote Harry" />
推荐阅读
- mysql - TYPO3 9.5 存储库查询以获取具有多个 sys_categories 的元素
- android - Listview 中的按钮不起作用
- python - 如何按索引创建具有行中值的数据透视表
- ruby-on-rails - 在 Ruby on Rails 中,如何拦截 Devise gem 的电子邮件发送功能并将其更改为调用 API?
- c# - 两个网格单元之间的距离,没有对角线
- webrtc - 如何在 a-frame 内实现实时视频流?
- c# - 是否可以在 Azure WebApp 中托管的 ASP.NET-WebAPI 项目中使用 ActiveX 组件?
- regex - 正则表达式 - 专门用于 Excel VBA 的 URL 正则表达式
- sql - 对整个列执行一次查询,而不是遍历所有单元格
- java - OffsetDateTime 中的 Z 偏移量是多少?