You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在@Url.Action中row.nodeId返回十六进制字符串而非整数,求修正方案

问题描述

原代码中,row.nodeId返回的是十六进制字符串,但后端DownloadFile接口的fileId参数需要整数值,导致参数传递不符合要求:

function iconFormatter(value, row, index) {
    var idNode = row.nodeId;
    if (row.isFile === true) {
        return '<img src="../Test/file.png" style="margin-left: 10px;" /><a class="file-download" href="@Url.Action("DownloadFile", "Casename", new { fileId = "' + row.nodeId + '" })"> ' + value + '</a>'
    }
    return value
}
修正方案

使用JavaScript的parseInt()函数将十六进制字符串转换为十进制整数,指定第二个参数为16以确保正确解析十六进制格式:

function iconFormatter(value, row, index) {
    var idNode = row.nodeId;
    if (row.isFile === true) {
        // 把十六进制字符串转为十进制整数
        const decimalFileId = parseInt(row.nodeId, 16);
        return '<img src="../Test/file.png" style="margin-left: 10px;" /><a class="file-download" href="@Url.Action("DownloadFile", "Casename", new { fileId = "' + decimalFileId + '" })"> ' + value + '</a>'
    }
    return value
}

补充说明

  • 若后端接口允许直接接收十六进制字符串作为fileId参数,也可以不做转换,只需将后端的fileId参数类型改为字符串即可;但如果明确要求整数,上述转换方案更适配。
  • 为避免row.nodeId出现非十六进制格式的异常值导致转换失败,可添加简单校验:
const decimalFileId = /^[0-9A-Fa-f]+$/.test(row.nodeId) ? parseInt(row.nodeId, 16) : row.nodeId;

内容的提问来源于stack exchange,提问作者Akshay Meshram

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 20:02:05