---
title: "How to apply Where Clause condition in foreach loop in MVC razor view?"  
description: "How to apply Where Clause condition in foreach loop in MVC razor view?"  
author: "Anonymous User"  
published: 2017-12-18  
updated: 2017-12-18  
canonical: https://www.mindstick.com/forum/34407/how-to-apply-where-clause-condition-in-foreach-loop-in-mvc-razor-view  
category: "c#"  
tags: ["asp.net mvc", "mvc", "mvc4", "razor"]  
reading_time: 2 minutes  

---

# How to apply Where Clause condition in foreach loop in MVC razor view?

Hi,

Below is my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii),

```
 @foreach (var item in Model)
                        {
                            if (item.Type == "Technical") {
  <a style="margin-bottom:30px" class="text-white contentFontSize" href="@Url.Action("Index", "Question", new { FilterBy = "technology", FilterText = item.Technology, Type = "Technical" })">
                                 <span class="float-left col-md-2" style="padding: 20px; text-transform: uppercase">@item.Technology  &nbsp;&nbsp;  @item.TotalCount </span>
                            </a>
   }
                        }
```

I want to write my conditional statement in [foreach](https://www.mindstick.com/forum/33870/how-parallel-foreach-works-internally) loop. It is possible to write a conditional statement with foreach loop. [If yes](https://www.mindstick.com/forum/159589/can-we-crash-jvm-if-yes-then-how) please give me some idea.

## Replies

### Reply by Hemant Patel

Hi Shaan,

Of course, you can write your conditional statement within foreach loop using where clause. Please follow the line of code.

```
 @foreach (var item in Model.Where(x => x.Type == "Technical"))
                        {
                            <a style="margin-bottom:30px" class="text-white contentFontSize" href="@Url.Action("Index", "Question", new { FilterBy = "technology", FilterText = item.Technology, Type = "Technical" })">
                                <span class="float-left col-md-2" style="padding: 20px; text-transform: uppercase">@item.Technology  &nbsp;&nbsp;  @item.TotalCount </span>
                            </a>
                        }
```

I hope its informative...


---

Original Source: https://www.mindstick.com/forum/34407/how-to-apply-where-clause-condition-in-foreach-loop-in-mvc-razor-view

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
