繁体   English   中英

使用Javascript中的参数访问@ URL.action

[英]Access @URL.action with Parameter in Javascript

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

脚本

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

Controller.cs

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

Route.cs

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

请帮帮我!!

谢谢!!

ControllerController.cs

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

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

Index.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>

就我而言。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM