Javascript C#mv5通过链接传递参数,然后将其显示在视图中

Javascript C#mv5通过链接传递参数,然后将其显示在视图中,javascript,c#,asp.net-mvc-5,Javascript,C#,Asp.net Mvc 5,如何在我的视图中获取pass参数。 我使用 <td> <a href="@Url.Action("report", "Map" , new { id = "Inventory"})" target="_blank"> Inventory Reports</a> </td> ../Map/report/Inventory url已显示传递数据,但如何在jquery或javascript中获取传递数据?您还可以使用lastIndexOf()函数查

如何在我的视图中获取pass参数。 我使用

 <td>
<a  href="@Url.Action("report", "Map" , new { id = "Inventory"})" target="_blank"> Inventory Reports</a>
</td>
../Map/report/Inventory


url已显示传递数据,但如何在jquery或javascript中获取传递数据?您还可以使用lastIndexOf()函数查找url中最后出现的/字符,然后使用substr()函数从该位置返回子字符串:

var value =this.href.substring(this.href.lastIndexOf('/') + 1);

警报(window.location.href.substring(window.location.href.lastIndexOf('/')+1))
您还可以使用lastIndexOf()函数查找URL中最后出现的/字符,然后使用substr()函数返回从该位置开始的子字符串:

var value =this.href.substring(this.href.lastIndexOf('/') + 1);

警报(window.location.href.substring(window.location.href.lastIndexOf(“/”)+1))
要使用路由中的参数,您可以通过视图模型或viewbag将其从控制器传递回页面,如果您只有这些:

public ActionResult report(string id)
{
  ViewBag.id = id;
  return View();
}
在您的视图中,您可以将值写入隐藏的输入

@Html.Hidden("id", ViewBag.id)
然后,在JavaScript中,您可以读取id值并根据需要使用它

var id = document.getElementsByName("id")[0].value;

要使用路由中的参数,您可以通过视图模型或viewbag(如果只有这些)将其从控制器传递回页面:

public ActionResult report(string id)
{
  ViewBag.id = id;
  return View();
}
在您的视图中,您可以将值写入隐藏的输入

@Html.Hidden("id", ViewBag.id)
然后,在JavaScript中,您可以读取id值并根据需要使用它

var id = document.getElementsByName("id")[0].value;

我想您已经使用了公共操作结果报告(字符串id)(id=URL参数)。当控制器返回视图时,您希望看到什么?我只需要获取javascript中的pass值。使用ViewBag/ViewData并将其放入JS中,如下所示:
var id='@ViewBag.id'
(或使用viewmodel)。谢谢您的帮助。我想您使用的是
公共操作结果报告(字符串id)
(id=URL参数)。当控制器返回视图时,您希望看到什么?我只需要获取javascript中的pass值。使用ViewBag/ViewData并将其放入JS中,如下所示:
var id='@ViewBag.id'
(或使用viewmodel)。谢谢您的帮助。