Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi everyone,

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

C#
//ExportController
               public ActionResult Export(string searchString, int searchOrder = 0)
               {

                   var user = from m in db.Orders select m;

                   Response.AddHeader("Content-Type", "application/vnd.ms-excel");
                   return this.View(user);
               }


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

C#
//Index.cshtml
               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/vnd.ms-excel");
                   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
Updated 8-Oct-12 2:20am
v4

1 solution

What about a for-loop?
Example:

C#
for(i = 0; i <= clientID; i++)
{
        //Code to generate your file here
}
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900