I have the following code which lists categories:
<div class="row" ng-show="!TemCategoria">
<div class="container" id="categoria" style="float:right" ng-hide="TemCategoria">
<select class="btn btn-warning pull-right" onchange="window.location.href=this.value" style=" margin-right: 20px" ng-show="!TemCategoria">
<option selected ng-show="!TemCategoria">@Model[0].CategoriaAtual.ToString()</option>
@for (int i = 0; i < Model[0].CategoriaId.Count; i++)
{
<option ng-show="!TemCategoria" style="color:#000; background-color:white" value="@Url.Action("Index", "Produto", new {CategoriaId = Model[0].CategoriaId[i], area = "Lojista" })">@Model[0].NomeCategoria[i]</option>
}
</select>
</div>
I'm assigning the value to the variable TemCategoria
like this:
@{
var TemCategoria = @Model[0].TemCategoria;
}
I need when there is no category the code simply does not appear and is not interpreted, because I get an error because category is empty.
I tested it when it has category and it hides if I put ng-show="TemCategoria"
and it shows if I put ng-show="!TemCategoria"
but when there is no category it simply gives the null variable error, it simply ignores ng-show
, should I do to resolve this?
Ps :. I put TemCategoria
in all to test.