简体   繁体   中英

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
However, the galleryItemsModel object is null when I hit the controller breakpoint.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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