简体   繁体   English

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

[英]Url.Action passing List object to controller action

@{
    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
}

I'm trying to pass a list of GUID's to my controller for download, the items are being added to the list & returns a count of 2 我正在尝试将GUID的列表传递给我的控制器以进行下载,这些项正被添加到列表中并返回2
However, the galleryItemsModel object is null when I hit the controller breakpoint. 但是,当我达到控制器断点时,galleryItemsModel对象为null。

  @{ 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; } } 

Passed as a list of strings! 作为字符串列表传递!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM