0

I am developing web application using asp.net mvc. I have following requirement.

  • My Index method gives me list of products on homepage.
  • I need to get page size as per the current browser resolution. (i.e if 1600*900 page size will be 12)
  • For that i am calling one Action Method and from its View i am setting page size using ajax call by getting inner width using JQuery and that ajax call saves the page size in session.
  • Is there any method or way i can call this view before the Index method? And then redirect again on Index method?
1
  • You can create a constructor for your controller, or an application controller that you inherit in every controller. Commented Mar 25, 2014 at 12:16

1 Answer 1

1

It's called the request-response cycle for a reason. What's you're talking about is basically doing a request-response-response, which is not possible.

What you could do is check for the existence of a cookie with the browser resolution in your actual action. If it's not set, then redirect to the action with the AJAX call. However, you can't use AJAX for this. Instead, there, set a cookie with the browser resolution and then set location.href to the actual URL the user should have gone to in the first place. This will essentially cause another redirect to the real action, which will now see the cookie.

I should note however, that this is extremely convoluted and isn't actually effective. What if the user then resizes their browser, after the fact? Something like number of items shown per page, should not be dependent on screen resolution. If you want to present a better experience, use CSS media queries to customize the display of the items for the resolution, so everyone gets the same function, just in different forms, optimized to their display.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.