首页 > 解决方案 > 使用 ActionLink 将目录的值从锚标记传递到控制器

问题描述

我正在尝试使用 ActionLink 从锚标记获取目录/文件夹的值到我的控制器。我已经对值进行了编码,但它总是给我 404 错误。

{item.Folder} 的链接文本/值:\\webserver01\business\application

我得到的值:%5C%5Cwebserver01%5Cbusiness%5Capplication

原来的

@Html.ActionLink(item.Folder, "OpenFolder", new { id = item.Folder }, new { @class = "", @target = "_blank" })

第二种解决方案

@Html.ActionLink(item.Folder, "OpenFolder", new { id = HttpUtility.UrlDecode(item.Folder) }, new { @class = "", @target = "_blank" })

第三个解决方案

@Html.ActionLink(item.Folder, "OpenFolder", new { id = item.Folder.Replace("%5C" "\\" }, new { @class = "", @target = "_blank" })

第四种解决方案 - 将 %5C 替换为 100,然后将 100 替换为 Controller 中的 \\。

@Html.ActionLink(item.Folder, "OpenFolder", new { id = item.Folder.Replace("%5C" "100" }, new { @class = "", @target = "_blank" })

给我价值的 4 个解决方案:%5C%5Cwebserver01%5Cbusiness%5Capplication

笔记:

标签: htmlasp.net-mvcrazor

解决方案


如果我理解正确,您正在尝试将 item.folder 的内容发送到控制器中的操作?

如果是这样,请考虑制作一个带有 item.folder 文本字段的表单。表单方法可以是 Get 而不是 Post。


推荐阅读