我希望带有参数的 @ URL.Action 的网址。 这是我的代码,但我从中得到空白值。
脚本
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 });
请帮帮我!!
谢谢!
答案 0 :(得分:0)
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>
适用于我的情况。