全部
我在控制器上定义了以下路由/操作:
I have the following route/action defined on my controller :
[RoutePrefix("widgets/download-functions")] [Route("download/{publishedReportId}"), HttpGet] public ActionResult Download(int publishedReportId)在我的js代码中,我想使用适当的ID创建一些路由.
And inside my js code, I want to create some routing with the appropriate id.
这是我的js代码中包含的内容(不起作用).我想念什么?
This is what I have inside my js code (which doesn't work). What am I missing?
self.downloadFile = function (data) { console.log(data); console.log("@(Url.Action("Download", new { publishedReportId = 9999 }))"); console.log("@(Url.Action("Download"))"); };对于这些东西和学习还是新手,我相信这很简单.
Still new to this stuff and learning, I am sure it is something simple.
运行此代码时,我将在控制台中看到以下内容
When I run this code, I get the following in the console
控制台输出
Thxjonpfl
Thx jonpfl
推荐答案如果您使用的是Url.Action,它没有利用属性路由,则需要遵循原始的路由方法,即使用,操作,控制器,区域和参数,以获取用于生成网址的扩展方法.
If you are using Url.Action, it doesn't take advantage of attribute routing, you will need to follow the original method of routing, which is to use, Action, Controller, area and params to get the extension method to produce the url.
[RoutePrefix("widgets/download-functions")] public class WidgetDownloadController : Controller...
[Route("download/{publishedReportId}"), HttpGet] public ActionResult Download(int publishedReportId)您将获得一个类似Url.Action的操作
You would get a Url.Action like:
console.log("@(Url.Action("Download","WidgetDownload", new { publishedReportId = 9999 }))");此外,这仅适用于由剃刀引擎(即)解析的脚本.直接在视图中编写的脚本.
Also, this will only work on scripts that are parsed by the razor engine, ie. scripts that are written directly in the view.
更多推荐
使用URL.Action时出现路由问题
发布评论