我想将路由传递给 Controller 操作。例如,如果我有一个 Controller 操作 /Files/Index
,我想将路由传递给 Controller ,例如 /Files/some/path/here
这样我的Index
操作选择 /some/path/here
。这可能吗?
public class FilesController : Controller
{
public HttpResponseMessage Index(string route)
{
// `route` should contain everything
// after the controller action
}
}
最佳答案
最直接的方法是使用像这样的查询字符串
http://www.website.com/Home/Index?route=%2fFiles%2fsome%2fpath%2fhere
或作为操作链接中的参数
@Html.ActionLink("Go To Index", "Index", "Home", new {route= HttpUtility.HtmlEncode(/Files/some/path/here)}, null)
确保像上面那样转义/
字符
关于c# - 将路由传递给 Controller 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24876578/