2

我想要带有参数的@URL.Action URL。这是我的代码,但我从中得到了空白值。

脚本

var OpenURL = ' @Url.Action("Document", "Controller", new { ID= "-22" })';
alert(OpenURL); // Value of this is coming blank

控制器.cs

public ActionResult Document(int? ID)
{
     return View();
}

路由.cs

 routes.MapRoute("Document", "OpenDocuments/{ID}", new { controller = "Controller", action = "Document", ID= UrlParameter.Optional });

请帮帮我!!

谢谢!!

4

1 回答 1

0

控制器控制器.cs

public class ControllerController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Document(int? ID)
        {
            return View();
        }
    }

索引.cshtml:

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
<script>
    var OpenURL = ' @Url.Action("Document", "Controller", new { ID= "-22" })';
    alert(OpenURL); // Value of this is coming blank
</script>

在我的情况下工作。

于 2013-06-26T11:06:31.963 回答