首页 > 解决方案 > 单击任何按钮后如何禁用/隐藏所有按钮(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>

标签: htmlasp.netrazor

解决方案


您需要表单的操作属性action="youraction/controller here" 并在您的操作中编写一些显示值的 C# 代码返回列表(“无”或“”)并在 cshtml 中添加style="display:@display"

<input id="Harry" name="submit" type="submit" style="display:@display" value="Vote Harry" />

推荐阅读