Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.11/5 (2 votes)
See more:
Hi Everybody.
I have an action method in a controller as below:
public async Task<ActionResult> abc()
        {
            string nexturl = "this is a dynamic value"
            ViewBag.Data = nexturl;

            return View();
        }

Where above Action Method does some data checking then pass a value to the View and return a specific view. Within the view If I scroll down to 60px I'll be redirected to another action method in controller which is as below:

public async Task<ActionResult> abcGetMoreData(string nexturl)
        {
            if (nexturl != null)
            {
                // somme logic
            }
            ViewBag.Data = nexturl;
            return View("abc");
        }

Above action method takes a parameter which is fed by 'abc' view with ajax. then do some checking and sends back a new value for nexturl to the view. If the user scroll the next 60 px he/she will be redirect to the same action method 'abcGetMoreData' and continues until the nextUrl become null.
What I want is to make this thing easy for the user. I want to load all data in once so do user shouldn't scroll down to get more data. How can I achieve this?

What I have tried:

I haven't tried anything as far as I am very new to C# and MVC.
Posted
Updated 9-Feb-17 3:25am
Comments
Richard Deeming 8-Feb-17 14:00pm    
So change your abc action to load all the data in one go, and remove the AJAX calls to abcGetMoreData.

What's the question?
Barcelonista Naser 8-Feb-17 14:02pm    
I can't do that because I am retrieving data from facebook and I have to paginate through each sets of records by providing either the next cursor or next page link.
Karthik_Mahalingam 8-Feb-17 23:08pm    
Always use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.

1 solution

You do not need two separate action methods.
Just define one, with all the parameters required, and fire a AJAX event as the user controls to the same action. This action will return the pre-set number of records per user event i.e. scrolling 60px.
You don't need to run it multiple times, just when the user action is repeated.
 
Share this answer
 

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