Url.Action将List对象传递给控制器​​操作

时间:2018-06-29 00:40:36

标签: c# asp.net-mvc razor

@{
    string guid = null;
    List<GalleryItemsViewModel> galleryItemsViewModel = new List<GalleryItemsViewModel>();
    foreach (var item in Model.ListingGalleryItems.Where(x => x.IsFloorplan))
    {
        galleryItemsViewModel.Add(new GalleryItemsViewModel
        {
            FileGuid = item.FileGuid
        });

    }

    <div>galleryitems @galleryItemsViewModel.Count()</div>

    <a class="accent" href='@Url.Action("Download", "File", new { galleryItemsModel = galleryItemsViewModel, ID = Model.ID, fileGuid = guid, returnUrl = this.Request.RawUrl }, null)'>
        <img src='@Url.Content("~/images/optimisedImages/property-info/floorplan.png")' />
        Floorplan
    </a>
}

public ActionResult Download(List<GalleryItemsViewModel> galleryItemsModel, string fileGuid, int id, string returnUrl)
{
  //stuff
}

我正在尝试将GUID的列表传递给我的控制器进行下载,这些项正被添加到列表中并返回2的计数
但是,当我碰到控制器断点时,galleryItemsModel对象为null。

1 个答案:

答案 0 :(得分:0)

        @{
            string guid = null;
            string guidList = "";
            foreach (var item in Model.ListingGalleryItems.Where(x => x.IsFloorplan))
            {
                guidList += item.FileGuid + ",";
            }

            <a class="accent" href='@Url.Action("Download", "File", new { fileGuidList = guidList, ID = Model.ID, fileGuid = guid, returnUrl = this.Request.RawUrl }, null)'>
                <img src='@Url.Content("~/images/optimisedImages/property-info/floorplan.png")' />
                Floorplan
            </a>
        }

public ActionResult Download(string fileGuidList, string fileGuid, int id, string returnUrl)
{
    string[] items = fileGuidList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

      foreach(var item in items)
      {
          fileGuid = item;
      }
}

作为字符串列表传递!