Prabhu
Prabhu

Reputation: 13335

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

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.

Upvotes: 0

Views: 1400

Answers (2)

Afzaal Ahmad Zeeshan
Afzaal Ahmad Zeeshan

Reputation: 15860

You're right! The code you're using will always provide you with the Screen's pixels. That are counted to be 1080.

To get the CSS values, you can use JavaScript instead!

You cannot read the values on run time. Because ASP.NET don't deal in that!

I can give you a simple suggestion:

Try this:

var wid = screen.width;

Now you can write it in the document!

Upvotes: 1

ramiramilu
ramiramilu

Reputation: 17182

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.

Upvotes: 1

Related Questions