Url.Action передает объект List в действие контроллера - PullRequest
0 голосов
/ 29 июня 2018
@{
    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 становится нулевым, когда я достигаю точки останова контроллера.

1 Ответ

0 голосов
/ 29 июня 2018

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

Передано как список строк!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...