How to get the CSS width of a mobile device in ASP.NET MVC?


Tags: html,asp.net,css,asp.net-mvc,asp.net-mvc-4

Problem :

In ASP.NET MVC, how do I get the width of the screen in terms of css pixels? I'm on a Nexus 5, and if I do Request.Browser.ScreenPixelsWidth, it gives me the width in terms of the pixel density (that is 1080), but what I am trying to get is the CSS width, should be more like 480px.



Solution :

One solution is to simply use JQuery's Window Width - $(window).width() - populate that in to the hiddenfield and you can get it on the server side in FormCollection.


    CSS Howto..

    how to add a border-radius css curl

    Slide up/down effect with ng-show and ng-animate

    How to access CSS children properly?

    How can I get the current state of my div animation?

    how can i get a css table-cell link not to stretch the clickable area

    how to remove space from html using bootstrap

    How to set two divs side-by-side with the same height?

    How to get table to overflow within a flex div?

    How to use Bootstrap CDN?

    How to change background Image sizing

    How to hide elements with css using checkboxes: different outputs according to element id or class?

    How does one load a CSS framework in Rails 3.1?

    How to add shadow to reverse c radial gradient only at the edges?

    How do I make a CSS sprite that controls multiple background images for multiple DIV's?

    Only show text on image when you hover - wordpress theme

    css - I've got a nested floating div, how do I get it to fill the entire 100%?

    how to make a responsive website using html/css and javascript [duplicate]

    how to put img inside circle in html and css?

    how to add a CSS class inside a JavaScript setup code?

    how to remove css property “element{}” [closed]

    How can I work around IE7 being unable to style dynamic elements created via DOM api

    How to override facebook share button css

    How to change an input button image using CSS?

    How to assign CSS background image properties mixing classes and ids

    How can I prevent the Featherlight lightbox from creating recursive dialogs?

    How to recreate Mac like File Browser in all OS with JS/CSS

    How can I extend the width of a child div to go beyond the parent div's width?

    CSS parallax effect. How to change the top margin

    Rails - how to add css to a helper method

    How to fix parent hover issues with CSS?