【发布时间】:2019-06-15 09:37:45
【问题描述】:
在 ASP.NET Core 2.2 控制器上,我有以下内容:
var url = _linkGenerator.GetUriByAction(HttpContext, action: "GetContentByFileId", values: new { FileId = 1 });
我在Controller中注入了LinkGenerator ...
现在我需要在一个不是控制器的类中生成 url,所以我尝试了:
var url = _linkGenerator.GetUriByAction(action: "GetContentByFileId", controller: "FileController", values: new { FileId = 1 });
但是,我收到消息说我需要更多参数。为什么?
在控制器之外使用 LinkGenerator 的正确方法是什么?
【问题讨论】:
标签: c# asp.net-core asp.net-core-2.2