asp.net - asp-route-id:传递的整数变为0
问题描述
我有以下问题。我有一个产品,我对其进行了一些测试。在我的 cshtml 页面中,我展示了一些产品项目的测试运行,如下所示:
<td><a asp-action="TestDetail" asp-route-id="@Model.ResultViewModels[i].TestRunId">Content</a></td>
TestRunId 是一个整数。例如,TestRunId 可能是 9。这有效:URL 看起来正确。在我的 cshtml 页面中,用户可以点击它来查看更多详细信息。
但是,当我在控制器中记录 asp-route-id 时,这个 TestRunId 似乎“丢失”了。在下面的示例中,第二个日志记录显示testrunId: 0
. 我希望这也是 9。
public IActionResult TestPlanRunDetail(int TestRunId)
{
logger.LogInformation("TestPlanRunDetail function called.");
logger.LogInformation("TestRunId: " + TestRunId);
// Omitted for brevity
return View(detail);
}
解决方案
里面的参数名asp-route-xxx
必须和后端的参数名一致(int xxx)
因此,更改您的参数名称之一以匹配另一个
推荐阅读
- php - 组合字母数字时如何选择真值?
- java - 在 Intellij (Linux - VM) 中创建 Maven 项目时出错
- spring - 无法使用spring hibernate在broswer上显示数据。下面是我的代码和输出
- python - 将亚马逊美食评论数据集从 kaggle 加载到 colab 笔记本中
- powershell - 如何将特定的 WMIobject 驱动程序解析为字符串?
- python - 使用烧瓶服务器时从 html 写入 python 文件的更改
- c# - 如何强制验证 UserControl?
- asp.net - 尽管视图模型已更新,但在 POST 后视图未更新
- elasticsearch - 添加任何自定义实体后的 jHipter Elasticsearch 问题
- docker-compose - NGINX 反向代理不适用于其他 docker 容器