0

In CSS you can modify your classes when the client (IPhone, ...) changes its orientation

@media only screen and (orientation:portrait)

Is there a way to detect this change in a MVC3 application?

I was searching for request parameters or header values but without success.

fuchs777
  • 993
  • 1
  • 14
  • 30

1 Answers1

2

The code behind your MVC site is server-side, and the orientation of the display is a client-side concern. There will not be anything in the HTTP headers about the screen orientation as they are sent from the server to the client. Therefore there is no way for the server to know anything about the display on the client, so this is not possible using MVC alone.

As you have said the only method available to use is javascript or CSS media queries.

Community
  • 1
  • 1
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • javascript was a good tip I found some code to get the orientation http://stackoverflow.com/questions/5284878/how-do-i-correctly-detect-orientation-change-using-javascript-and-phonegap-in-io/9824480#9824480 I simply post the current orientation to my application `function UpdateOrientation(neworientation) { $.post('@Url.Action("DoUpdateOrientation")', { orientation: neworientation }); };` – fuchs777 Apr 12 '12 at 12:14
  • Ok the script has a little flaw... On my phone it works just fine but in a normal browser window.orientation is undefined. I switched the case to 0 -> portait and default -> landscape. – fuchs777 Apr 12 '12 at 12:31
  • You should ask a new question if you want to discuss the script you've got. – Rory McCrossan Apr 12 '12 at 12:35
  • The script fulfills all my needs now. I just wanted to share my results. In case no one has a better solution I could edit the full script and code in my question. – fuchs777 Apr 12 '12 at 13:29
  • Accepted your answer because its correct and helped me to find a solution. (Should I edit my result in the question or post a new answer?) – fuchs777 Apr 16 '12 at 07:11