简体   繁体   English

如何隐藏和显示 asp.net core razor 页面中未在 c# 中的服务器命令中运行的按钮?

[英]how to hide and show button in asp.net core razor page which are not have run at Server command in c#?

I have two buttons on the asp.net core razor page as shown below code:我在 asp.net core razor 页面上有两个按钮,如下代码所示:

 <div class="row div-form-control">
                <div class="col-md-12">
                    <div class="form-group actions">
                        
                        <button type="button" name="submit" id="submit" class="btn btn-primary" action="save"><i class="icon-floppy-disk position-right"></i>Submit</button>
                        <button type="button" class="btn btn-primary" action="search"><i class="icon-new-tab position-left"></i>Search</button>

                    </div>
                </div>
 </div>

now I want to hide Submit Button in C# when the User Role is not an Admin like:现在,当用户角色不是管理员时,我想在 C# 中隐藏提交按钮,例如:

string Role="NormalUser";
if(Role!="Admin"){
 submit.Visibility = Visibility.Hidden;
}

but it does not work because in submit button I don't have Runat="Server" I want to hide it without using Ranat="Server" by JavaScript or Another Method Can anyone help me how to do it?但它不起作用,因为在提交按钮中我没有 Runat="Server" 我想隐藏它而不使用 JavaScript 或其他方法的 Ranat="Server" 谁能帮我怎么做? Thanks谢谢

one way to do it is like:一种方法是:

@if(Role!="Admin"){
    <button type="button" name="submit" style="display:hidden;" id="submit" class="btn btn-primary" action="save"><i class="icon-floppy-disk position-right"></i>Submit</button>
}else{
    <button type="button" name="submit" id="submit" class="btn btn-primary" action="save"><i class="icon-floppy-disk position-right"></i>Submit</button>
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 ASP.NET C# 的 Index.csthml 中显示和隐藏 div 标签? - How to show and hide div tag in Index.csthml in ASP.NET C#? 我应该如何获取表单的输入,并将该输入发送到 C# 类? ASP.Net Core - Razor 页面 - How should I get the Input of a Form, and Send that Input to a C# class? ASP.Net Core - Razor Pages 仅刷新 ASP.NET CORE Razor 页面中的内容页面 - Refresh only content page in ASP.NET CORE Razor Pages 如何使用 c# 在 asp.net 中隐藏和显示警报 - How to hide and display alert in asp.net using c# 如何对ASP.NET Core 2.0剃须刀页面中按下的按钮做出反应 - how to react to button pushed in ASP.NET Core 2.0 razor pages ASP.NET Server不会将页面重新发送到C#WebMethod上的客户端 - ASP.NET Server not resending page to client on C# WebMethod 如何提交 asp.net 核心 razor 页面表单而不重新加载页面 - How to submit asp.net core razor pages form without reloading page 如何单击div中的按钮以不刷新整个页面asp.net C# - how can I click on button inside div to not to refresh whole page asp.net C# 如何创建动态生成的按钮,以在ASP.Net C#中使用javascript调用服务器端方法 - how to create dynamicly generated button that call server side method in using javascript in ASP.Net c# ASP.NET - 如何使用 MVC 模式通过服务器端代码 (C#) 加载页面? - ASP.NET - How to load page via server-side code (C#) with MVC Pattern in place?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM