Click here to Skip to main content
13,048,584 members (91,109 online)
Rate this:
Please Sign up or sign in to vote.
Hi everyone,

I have a simple method wich generate a file based on a view (Export.cshtml) to format data.

               public ActionResult Export(string searchString, int searchOrder = 0)
                   var user = from m in db.Orders select m;
                   Response.AddHeader("Content-Type", "application/");
                   return this.View(user);

In the following code, I added a if condition to select a clientID.

               public ActionResult Export(string searchString, int searchOrder = 0)
                   var user = from m in db.Orders select m;
                   if (!String.IsNullOrEmpty(searchString))
                       user = user.Where(s => s.ClientID.Contains(searchString));
                   Response.AddHeader("Content-Type", "application/");
                   return this.View(user);

In this case, in my Index.cshtml view, I enter an ID in a textbox, and when I click on a submit button, it generate a file with only the lines that match this ID.

I would like, when I click the submit button, it retrieves me a file for each clientID in my table, because if I have more than 10.000 clientID, I won't enter an ID and click on submit 10.000 times.

I hope I was clear enough, sorry for my english and thanks in advance for your answers, tips, link, anything... I'm really stuck.
Posted 8-Oct-12 1:41am
Updated 8-Oct-12 2:20am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

What about a for-loop?

for(i = 0; i <= clientID; i++)
        //Code to generate your file here
AlternativeThought 8-Oct-12 9:13am
First of all, thanks for your reply.

I don't see how it would work, what clientID represent in your example ? Maybe if I have a list with all my clientID I could do something like that

for(int i = 0, i <= listClientId.Count(), i++) and then apply the code to generate a file on each item in the list. I thought about it, but I don't know how implement something like that...

And also, my clientID are strings, but this is not the main issue. I'm a beginner in asp so I don't have a large vision of all possibilities...
AlternativeThought 9-Oct-12 4:25am
Moreover, my method is an ActionResult so I am obliged to return a my view. So if I put my code in the for loop, what am I supposed to return outwards the loop ?

Is it possible to write a method which call my Export() ActionResult method for each clientID in my table ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100