C# MVC 路由传参的问题

2019-07-25 17:13:03 +08:00
 whoami9894

遇到某 C#项目

路由配置: RouteConfig:

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

这里有个 FileController 中的函数,签名为public AResult Fetch(string url),需要传 URL 参数,我尝试 URL 编码了/:.等字符但好像还是有问题,这里正确方法应该如何调用?

同样的还有一个 Delete 函数:

public void Delete(string filePath)
{
    UploadCls.Delete(filePath);
}

public static bool UploadCls::Delete(string filePath)
        {
            try
            {
                File.Delete(filePath);
                return true;
            }
            catch { }
            return false;
        }

在参数中传..%2F服务器会一直无响应

6981 次点击
所在节点    C#
1 条回复
Pursue9
2019-07-26 12:34:59 +08:00
[HttpDelete("delete/{filePath?}")]
public IActionResult Delete([FromRoute]string filePath)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/586196

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX