Click here to Skip to main content
Rate this: bad
good
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.
 
//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.
 
//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 8-Oct-12 2:41am
Edited 8-Oct-12 3:20am
v4

1 solution

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

Solution 1

What about a for-loop?
Example:
 
for(i = 0; i <= clientID; i++)
{
        //Code to generate your file here
}
  Permalink  
Comments
AlternativeThought at 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 at 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
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 255
3 Shweta N Mishra 216
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2014
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