Bli*_*ers 6 asp.net-core asp.net-core-2.0 razor-pages
我可以使用锚标记助手转到不同的剃刀页面(从现有的剃刀页面),例如,这有效:
<a asp-page="./EditReport" asp-route-id="@report.IntegrityReportId" class="btn fa fa-edit"></a>
Run Code Online (Sandbox Code Playgroud)
我如何才能使用按钮来完成类似的工作。我努力了:
<button type="button" asp-route-data="@report.IntegrityReportId" asp-route="EditReport">EditReport</button>
Run Code Online (Sandbox Code Playgroud)
但页面永远不会加载。我还尝试使用具有不同变体的页面处理程序:
<input type="button" asp-page-handler="EditReport" asp-route="@report.IntegrityReportId"/>
Run Code Online (Sandbox Code Playgroud)
并关联(在页面cs文件中):
public ActionResult OnEditReport(int id)
{
return RedirectToPage("./EditReport", id);
}
Run Code Online (Sandbox Code Playgroud)
但这个方法永远不会被调用(我也尝试过命名方法 OnPostEditReport 但同样的问题。
如果有帮助的话,我原来的非 dotnet 核心应用程序可以很好地工作:
<button type="button" title="Edit report" class="btn btn-datatable fa fa-edit" onclick="location.href = '@Url.Action("EditReport", "Home", new {id = report.IntegrityReportID})'"></button>
Run Code Online (Sandbox Code Playgroud)
如有任何帮助,我们将不胜感激。谢谢。
我设法通过使用下面的锚点获得了我需要的效果 - 所以它看起来像一个按钮..
<a asp-page="./EditReport" asp-route-id="@report.IntegrityReportId" class="btn btn-default"><i class="fa fa-edit"></i></a>
Run Code Online (Sandbox Code Playgroud)
您不能仅使用一个按钮来重定向到其他没有 JavaScript 的 Razor 页面。您可以使用表单标签内的提交按钮来重定向到其他 Razor 页面。以下示例演示如何进行 GET 重定向,该重定向将重定向到“关于”页面:
<form method="get">
<button type="submit" asp-page="./About">Click me to go to the About page</button>
</form>
Run Code Online (Sandbox Code Playgroud)
如果您想要 POST 请求,请使用以下代码:
<form method="post">
<button type="submit" asp-page="./About">Click me to go to the About page</button>
</form>
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,您都可以定义路由值或处理程序以满足要求。
我希望它有帮助。
| 归档时间: |
|
| 查看次数: |
21140 次 |
| 最近记录: |