0

Hi I have the following code in razor:

@{
                foreach (var item in this.Model)
                {
                    if (item.Items == null)
                    {
                        @: <li @{if (item.Active) { <text> class="active" </text>   } }>

                       if (item.SpanClass == null)
                       {
                            @: <a href="@item.Url" @{ if (item.Active) { <text> class="waves-effect active" </text>    } else { <text> class="waves-effect" </text>     } }><i class="@item.Icon"></i><span> @item.Text </span></a>
                       }else
                       {
                            @: <a href="@item.Url" @{ if (item.Active) { <text> class="waves-effect active" </text>    } else { <text> class="waves-effect" </text>     } }><i class="@item.Icon"></i><span> @item.Text <span class="@item.SpanClass">@item.SpanValue</span></span></a>
                                        }

                        }
                        @: </li>
                     }
            }

It looks like this:

enter image description here

But I go to:

enter image description here

Then the code format is destroyed:

enter image description here

Any clue?

VAAA
  • 14,531
  • 28
  • 130
  • 253
  • You can simplify all this considerably by using a view model that includes properties for your class names - e.g. `
  • ` where `ClassName` is either "active" or `null` (in the case of `null`, then class name will be omitted from the html)
  • –  Nov 15 '16 at 02:10
  • For the link it would be ` –  Nov 15 '16 at 02:12
  • This might be of some help http://stackoverflow.com/a/4942145/1339516 – Searching Nov 15 '16 at 03:41