[英]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.