To pass Javascript values to Asp.net, a new request (e.g. using AJAX) is required. It is not possible to check the resolution before making the request because JS in this case is client-side, while Asp.net is server-side, which means that the JS code will only run in the browser after the request that downloaded the page is completed. The server does not have access to JS-independent code running in the browser, unless you inform it directly by making a new request.
But this approach is bad, because the decision whether or not to display a component in the navbar will be dependent on a second request after loading the page. The ideal is to do this with client-side technologies so you don’t have to go to the server and then come back, saving resources, accelerating page loading and not depending on JS enabled in the browser.
It is possible to do this with JS, but CSS3 introduced the media query, starting the movement of responsive layouts that automatically adjust according to the resolution (and the server is agnostic about it). For example, to hide a navbar when the resolution is less than or equal to 600px, do so:
@media (max-width: 600px)
{
.navbar {
display: none;
}
}
You plan to get the resolution to control the page layout?
– rodorgas
Yes, you already do this the time in the application. The most common is to use AJAX in these cases. I don’t even know which is duplicate of this, but it has been answered a few times: http://answall.com/search?q=%5Basp.net-mvc%5D+ajax
– Maniero
@rodorgas the idea is that I have a component in the navbar, and when the resolution decreased, the content was hidden
– Fabio Souza