简体   繁体   English

我正在尝试制作一个提交类型按钮,单击该按钮时,会将用户重定向到另一个 Razor 类型页面

[英]I'm trying to make a submit type button that, when clicked on, redirects the user to another Razor type page

I tried a solution I saw online but the function they gave me seems to, when the button is pushed, it redirects to me again.我尝试了一个我在网上看到的解决方案,但他们给我的 function 似乎是,当按下按钮时,它会再次重定向到我。

<div class="btn-block">
                <button type="submit" id="btnSubmit" OnClick="btnSubmit_Click" href="/">Send</button>
            </div>

This is how that button is written in html code.这就是该按钮在 html 代码中的编写方式。 The code in C# is this one: C# 中的代码是这个:

protected IActionResult btnSubmit_Click(object sender, EventArgs e)
        {
            return RedirectToPage("L_page");
        }

My goal is to make the button, when clicked, redirect to a Razor page called L_page.我的目标是使按钮在单击时重定向到名为 L_page 的 Razor 页面。 Can you give me some tips or another funcion to use?你能给我一些提示或其他使用的功能吗?

Note: I'm new at making websites and using ASP.NET so any other advice will be welcomed.注意:我是制作网站和使用 ASP.NET 的新手,因此欢迎任何其他建议。

onclick like that is a client-side thing, it will bind to a javascript function in the browser. onclick像这样是客户端的东西,它将绑定到浏览器中的javascript function。 If that's what you want you could do this如果这就是你想要的,你可以这样做

<div class="btn-block">
                <button type="submit" id="btnSubmit" onclick="clickHandlerInBrowser()">Send</button>
</div>
<script>
function clickHandlerInBrowser(){
   window.location.href = "http://www.w3schools.com"; //or e.g. "L-page.html"
}
</script>
<input type="button" value="btnSubmit" onclick="window.location.href='<%= Url.Action("actionName", "controllerName") %>';" />

If you are using asp.net core mvc:如果您使用的是 asp.net 核心 mvc:

1.asp-controller,asp-action: 1.asp-controller,asp-action:

<a asp-controller="ControllerName" asp-action="ActionName">Send</a>

2.href: 2.href:

<a href="/xxx/xxx">Send</a>

If you want to use button,you can also do like this:如果你想使用按钮,你也可以这样做:

<form asp-controller="ControllerName" asp-action="ActionName">
<button type="submit" id="btnSubmit">Send</button>
</form>

If you are using asp.net core razor page:如果您使用的是 asp.net 内核 razor 页面:

1.asp-page: 1.asp页面:

<a asp-page="../ControllerName/ActionName">Send</a>

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

相关问题 因此,我试图在Visual Studio中制作一个C#程序,当单击“下一步”按钮时,该程序将移至新页面 - So I am trying to make a C# program in visual studio which moves onto a new page when the “next” button is clicked 试图使一个按钮在单击另一个按钮时显示某些内容(C#) - Trying to make a button display something when another button is clicked (C#) 单击按钮时动态添加相同用户控件类型的多个实例 - Dynamically add multiple instances of the same user control type when button is clicked 单击按钮C#WPF时直接定向到另一个xaml用户控制页面 - Direct to another xaml user control page when button clicked C# WPF 输入提交与输入按钮 - type submit vs type button 单击用户控件中的另一个按钮时更改用户控件 - Changing User Control When Another Button in a User Control is Clicked 如何从Razor html(Umbraco)访问用户类型 - How can I access user type from Razor html (Umbraco) 我正在尝试制作一个在输入触发器后单击按钮时总是会发生的动画 - I'm trying to make an animation that can always happen when clicking a button after entering a trigger 单击表单按钮时,Asp-Page-Handler 不会触发 Razor 模型中的方法 - Asp-Page-Handler not firing Method in Razor Model when Form Button is Clicked 单击按钮时无法查看所有文件类型图像 - not able to see all file type images at a time when button clicked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM