How can I make that so it will work only one condition at one time? Basically there is a time when A,B, and C can be pick at one time all of them. Example: So if you pick A there should be only one posibility and it is "else if (A != null)", but if there is A and B it should display only "else if (Model.B != null)", but if it is A,B, and C it should display only "else if (Model.SoldOut != null)". So is there any way to do that? Or is there any way to delete A when it display B, and delete A and B when it displays C?
@if (A == null & B == null & C == null)
{
@Resources.Undefined;
}
else if (A != null)
{
@Resources.ResourceManager.GetString(Model.A.GetDisplayValue());
}
else if (Model.B != null)
{
@Model.B
}
else if (Model.SoldOut != null)
{
<p>-</p>
}
CodePudding user response:
You can do it by changing the order of else if statements
@if (A == null & B == null & C == null)
{
@Resources.Undefined;
}
else if (Model.SoldOut != null)
{
<p>-</p>
}
else if (Model.B != null)
{
@Model.B
}
else if (A != null)
{
@Resources.ResourceManager.GetString(Model.A.GetDisplayValue());
}
CodePudding user response:
My attempt at what you're describing is as follows. It's an inversion of your logic.
// IF THEY'RE ALL PICKED
// it should display only "else if (Model.SoldOut != null)"
@if(A && B && C)
{
<p>-</p>
}
// it should display only "else if (Model.B != null)"
else if(A && B)
{
@Model.B
}
// there should be only one posibility and it is "else if (A != null)"
else if(A)
{
@Resources.ResourceManager.GetString(Model.A.GetDisplayValue());
}
else
{
@Resources.Undefined;
}
But, like I said in my comment, it's incredibly difficult to figure out the logic when you're not describing all of the potential cases. E.g. What if 'C' is the only one that's picked? You know?
