I’m trying to hack my way through some ASP.NET pages put together with Razor, having never seen Razor used before today, more or less, and I was wondering if it were possible to grab a CSS style value and use it in Razor code, like this:
@foreach (var item in someList.Where(i => someHTMLElement.display == block
? i.property == "value"
: i.property == "othervalue"))
{
... display filtered list
}
It’s that Where bit I’d like to populate with something useful. Any suggestions?
Razor runs on the server much earlier a DOM tree is constructed by the client browser. This means that you do not have access to other DOM elements with Razor. The best way to achieve that would be to simply adapt your view model and include the necessary properties to it and have the controller populate them. So in the view all you have to do is a simple test of some property.