使用@ url.action将列表/模型作为参数传递

时间:2017-12-14 15:35:09

标签: c# asp.net-mvc list model

有没有办法将列表作为@url.action的参数传递,还是有更好的解决方案?

伪代码: 除非我为我的模型或列表定义索引,否则这不会传递任何内容。

 @Url.Action("DeleteConfirmed", "Home", new { selectedids = /*model or list?*/ }, null)

我需要将列表或模型传递给它:

  public ActionResult DeleteConfirmed(List<int> selectedids) {

       //Code
       return View("Index");

  }

1 个答案:

答案 0 :(得分:0)

我将它们作为字符串加入,然后将其转换回服务器;这意味着selectedid需要是服务器上的字符串,您可以在逗号上进行字符串拆分并将每个值转换为long

@Url.Action("DeleteConfirmed", "Home", new { selectedids = String.Join(",", Model.IDS) })