asp.net - 如何使用 tr onlick 重定向到不同的 url
问题描述
我有这个 Razor 页面用户视图,其中包括表格中的学生列表
我想单击一行以打开一个 URL,该 URL 传递所选学生行的 ID。这是我到目前为止得到的
@foreach (var student in Model._User.Students)
{
<tr onclick="location.href = '@(Url.Action("Info", new { id = student.Id }))'">
<td>Some basic info of student</td>
</tr>
}
我希望被重定向到 /Info/{id} 但得到 /Useview/{id}?action=Info
解决方案
您可以使用Url.Page
:
<tr onclick="location.href = '@(Url.Page("Info", new { id = 1 }))'">
然后,如果您有另一个名为的页面Info
,则可以获取参数:
@page "{id}"
@model RAZOR.Pages.InfoModel
@{
ViewData["Title"] = "Info";
}
<p>The Id is @Model.Id</p>
信息.cshtml.cs:
public class InfoModel : PageModel
{
public int Id { get; set; }
public void OnGet(int id)
{
Id = id;
}
}
推荐阅读
- php - Laravel yajra/datatables & yajra/datatables 按钮
- c - 是否在 C 中移动有符号短未定义行为的有符号位?
- python-3.x - P值=0.000时是什么意思;使用 statsmodel 的 OLS 回归结果中的 Rsquared = 0.012;但是sklearn Rsquared = 0.839?
- c# - 如何在 .Net 中使用后台传输服务上传文件
- azure - Azure Powershell - 可以找到包但不能安装它
- javascript - 在 API 请求中指定父级
- angular - 以角度 6 在路由中传递两个参数
- c++ - 将宏作为 CString 引用传递
- kubernetes - Kubernetes 1.9 仪表板 v1.10.0 登录屏幕
- unit-testing - 起订量,如何使用私有构造函数来起订量对象?