1

I have a mvc.net project which works great.

I use this project as a filter that gets data, filters it and sends back a JSON.

Example of a calls made to this project could be like :

public ActionResult GetSomeData( )
{
    var data = new List<HelloWorld> ();
    TempData["imageData"] = data; // get data, filter it and send back part of it and save the rest in "TEMPDATA"

    var retunrdtd = new {Success = "hello world"};

    return new JsonResult {Data = filteredData, JsonRequestBehavior = JsonRequestBehavior.AllowGet};

}

I filter the data since the amount of data can be large so i send back lets say 100 listitems instead of all 10000. if i want a 100 more i call a method that checks if the tempdata exists and takes the remaining 9900 from tempdata and gives me another 100 etc.

Im thinking of creating a seperate web api that will be on another domain. I would like to call the methods that I have in my current project, example:

www.myFilterMvcDotNet.com/home/GetSomeData

But im not sure if the tempdata will hold any value once I got the first 100 listitems. So my question is simple, will it? if not what is the best way to keep track of data recived and remaining data?

CodeNotFound
  • 22,153
  • 10
  • 68
  • 69
ThunD3eR
  • 3,216
  • 5
  • 50
  • 94

1 Answers1

1

I filter the data since the amount of data can be large so i send back lets say 100 listitems instead of all 10000. if i want a 100 more i call a method that checks if the tempdata exists and takes the remaining 9900 from tempdata and gives me another 100 etc.

TempData is not used for what you're trying to do. TempData is like a ViewBag and the only difference with the latter is that TempData is persisted between redirection and all data in it are clear.

To solve your problem you might look at How to use Session in ASP.Net MVC ?

Community
  • 1
  • 1
CodeNotFound
  • 22,153
  • 10
  • 68
  • 69
  • Im far from an expert on this but it was under my understanding that sessions were only created if you actually visite the site? in my case i will just make a call to a method from another domain, i will not be visiting the site. Tempdata stores data between request i check if it is null in the method and if it is i store data in it for a new request. On the second request my tempdata has data in it i use it and store new tempdata again. – ThunD3eR Feb 11 '16 at 20:02
  • 1
    Using session is the right way to do what you need. Just replace TempData with Session. Read documentations about TempData you will see that. With Session you store the data for a specified lifetime with one request. With your actuel solution you are sending request each time the user need some data then there is no benefit to store data that will be lost. – CodeNotFound Feb 11 '16 at 20:06
  • Something just came to my attention. This will be used by multiple users, is seassion equipt to handle that? – ThunD3eR Feb 11 '16 at 20:13
  • 1
    It the data are shared by multiple users then Application Cache like explained here => http://stackoverflow.com/questions/343899/how-to-cache-data-in-a-mvc-application – CodeNotFound Feb 11 '16 at 20:15
  • the date will be used by multiple users. However If user one calls a method fom another domain and gets first 100 items. Calls the mthod again and gets 100 more. User 2 comes along and calls the method then he/she should get the first 100 not the 3:d 100. – ThunD3eR Feb 11 '16 at 20:23
  • 1
    Still continue to use Application cache. For your action add a parameter named index. If user first come the index parmeter must be 1 and in your collection do something like `myCollection.Take(index * 100)`. Each user will first pass a paramter index = 1 the first time then add by incrementing the index when calling your action. – CodeNotFound Feb 11 '16 at 20:27