Is it "legit" to use a Linq query in a razor view?
This is not an ideal way to do things. The model passed to your view should only have what you need for the view.

There are a few different things going on here. One is searching for the information and two is displaying it in your view. The solution will depend on the context in which it is happening.

One option is that you can change your service to be searchable on GroupId. This way only the information you need is passed back.

If you get an entire object back from your service and just want to filter the contacts on that more complex model, you could create a repository that does that filtering or use a ViewModel.

The main thing here is that you never want to do this type of filtering in your view. Only send your view the data that it needs.