My if function not wokring properly in ASP NET MVC5

Viewed 55

I try to make an if function in razor view, by comparing two data from viewbag in ASP NET MVC @ver comes from ViewBag.Temp

<td class="text-center">
    @foreach (Dummy ver in ViewBag.dummies)
    {
      if (@ver.Name == @item.Name)
      {
         <i class="fas fa-check" id="existed"></i>
      }
    }
</td>

I already have 2 same name data inside those 2 tables but it wont work

The Temp data

The Dummies Data

but when i call another data it works properly

Another data temp

Another data Dummies

1 Answers

It solved, there is some human error on the data that have white space on leading or trailing then im using trim() function on my view

look like this

<td class="text-center">
                        @foreach (Dummy ver in ViewBag.Dummies)
                        {
                                var tem = @item.Name.Trim();
                                if (@ver.Name.Trim() == tem)
                            {
                                <i class="fas fa-check" id="existed"></i>
                            }
                        }
                    </td>
Related