0

I have a large set of data that my users can filter by various options. I'd like to export this set of data as a CSV, but not sure how to send the item to my controller action.

The following code in my index.cshtml file:

@model Project.ViewModels.PeopleIndexViewModel
<a href="@Url.Action("Export", "Person", new { List = Model.People.ToList()})" title="Export to CSV">
    <img src="/content/images/excel.gif" />
</a>

Turns out to be empty when I hit the controller:

public ActionResult Export(List<Person> List)
{
    // List is empty here...
}

What am I doing wrong?

Robbie Mills
  • 2,705
  • 7
  • 52
  • 87
  • Make sure you've defined valid route in RouteConfig.cs file. To return csv file controller see below post http://stackoverflow.com/questions/23566595/download-file-from-fileresult-without-saving-to-disk/23570561#23570561 – malkam May 10 '14 at 12:51

1 Answers1

0

In my opinion it won't work that way. I would suggest keeping the List in Session or TempData like that:

Session["PeopleList"] = list;

or

TempData["PeopleList"] = list;

This way you might access it between requests. Remember - storage in Session is for Session duration. Storage in TempData is only till the next request unless you use Keep method.

mr100
  • 4,340
  • 2
  • 26
  • 38