[英]Access @URL.action with Parameter in Javascript
I want URL by @URL.Action with Parameter. 我想要通过带有参数的@ URL.Action的 URL。 Here is my code but i am getting blank value from it.
这是我的代码,但是我从中得到空值。
Script 脚本
var OpenURL = ' @Url.Action("Document", "Controller", new { ID= "-22" })';
alert(OpenURL); // Value of this is coming blank
Controller.cs Controller.cs
public ActionResult Document(int? ID)
{
return View();
}
Route.cs Route.cs
routes.MapRoute("Document", "OpenDocuments/{ID}", new { controller = "Controller", action = "Document", ID= UrlParameter.Optional });
please help me out!! 请帮帮我!!
Thanks!! 谢谢!!
ControllerController.cs ControllerController.cs
public class ControllerController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Document(int? ID)
{
return View();
}
}
Index.cshtml: 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>
Works in my case. 就我而言。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.