我可以使用定位标记帮助程序转到其他剃刀页面(从现有剃刀页面),例如这有效:
<a asp-page="./EditReport" asp-route-id="@report.IntegrityReportId" class="btn fa fa-edit"></a>
我如何使用按钮才能执行类似的操作。我尝试过:
<button type="button" asp-route-data="@report.IntegrityReportId" asp-route="EditReport">EditReport</button>
但是该页面永远不会加载。我还尝试使用具有以下不同变体的页面处理程序:
<input type="button" asp-page-handler="EditReport" asp-route="@report.IntegrityReportId"/>
和相关联(在页面cs文件中:
public ActionResult OnEditReport(int id)
{
return RedirectToPage("./EditReport", id);
}
但是此方法从未被调用(我也尝试过命名方法OnPostEditReport,但存在相同的问题。
如果有帮助,我的原始NON-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>
感谢您的任何帮助。谢谢。
您不能仅使用一个无需使用JavaScript即可重定向到其他剃须刀页面的按钮。您可以在表单标签内使用提交按钮,以重定向到其他剃刀页面。以下示例演示了如何进行GET重定向,该重定向将重定向到“关于”页面:
<form method="get">
<button type="submit" asp-page="./About">Click me to go to the About page</button>
</form>
如果您想要POST请求,请使用以下代码:
<form method="post">
<button type="submit" asp-page="./About">Click me to go to the About page</button>
</form>
在两种情况下,您都可以定义路由值或处理程序来满足要求。
希望对您有帮助。
通过使用下面的锚点,我设法获得了所需的效果-因此它看起来像一个按钮。
<a asp-page="./EditReport" asp-route-id="@report.IntegrityReportId" class="btn btn-default"><i class="fa fa-edit"></i></a>
我知道它晚了一年,但是您必须删除'type =“ button”',也请尝试删除'。'来自asp-page =“ ./ EditReport”。BR。
下面的解决方案在我的ASP.NET Core 3.1项目中对我有用:
<a class="btn btn-primary btn-sm" asp-page="./Edit" asp-route-id="@item.Id"><i class="fas fa-user"></i> Edit</a>
上面突出显示的代码全部在一行上,只是堆栈溢出提供答案的方式。注意,我选择在按钮中的文本之前显示图标,然后在按钮标签“编辑”之前添加了一个空白区域,以使按钮看起来更好看。