Note that there are some explanatory texts on larger screens.

plurals
  1. PONested if Statement does not follow "map"
    text
    copied!<p>I have a bit of an issue with some nested if statements. Here is what it looks like: </p> <pre><code>if (selectedlocat == "") { if (selectedfield == "") { } else { } } else { if (selectedfield == "") { } else { } } </code></pre> <p>It does not follow the "map" correctly. For some reason it always goes to the else statement in the else statement at the bottom. I know this because it gives me an error in that area, when it was never supposed to even get to that part of the code. </p> <p>What is going on, and how can I fix it?</p> <p><em><strong></em>**EDIT***</strong></p> <p>Alright, so let me do a little clarification:</p> <p>It is in a razor webpage, so debugging does me no good until I run into the error.</p> <p>The values are truly empty, I have a foreach inside of each if and else</p> <p>The whole story:</p> <p>I have a website in which I get data and I conditionally show it based on what the dropdown form is. the reason I think that it is in the nesting is that I had it working with one dropdown, but when I added the second one, I had to make it conditional. Here is the full code:</p> <pre><code> @{ if (selectedlocat == "") { if (selectedfield == "") { foreach (var row1 in db.Query(querypeople + order)) { &lt;tr&gt; &lt;td style="text-align:center; width: 110px"&gt;@row1.Last_Name, @row1.First_Name &lt;/td&gt; &lt;td&gt;@row1.Firm_Name&lt;/td&gt; &lt;td style="text-align:center"&gt;&lt;a href="http://@row1.Website"&gt;@row1.Website&lt;/a&gt;&lt;/td&gt; &lt;td style="text-align:center"&gt;@row1.Phone_Office&lt;/td&gt; &lt;td style="text-align:center"&gt;@row1.City_Phys&lt;/td&gt; &lt;/tr&gt; } } else { foreach (var row2 in db.Query(querypeople + where + field + selectedfield + app + order)) { &lt;tr&gt; &lt;td style="text-align:center; width: 110px"&gt;@row2.Last_Name, @row2.First_Name &lt;/td&gt; &lt;td&gt;@row2.Firm_Name&lt;/td&gt; &lt;td style="text-align:center"&gt;&lt;a href="http://@row2.Website"&gt;@row2.Website&lt;/a&gt;&lt;/td&gt; &lt;td style="text-align:center"&gt;@row2.Phone_Office&lt;/td&gt; &lt;td style="text-align:center"&gt;@row2.City_Phys&lt;/td&gt; &lt;/tr&gt; } } } else { if (selectedfield == "") { foreach (var row3 in db.Query(querypeople + where + city + selectedlocat + app + order)) { &lt;tr&gt; &lt;td style="text-align:center; width: 110px"&gt;@row3.Last_Name, @row3.First_Name &lt;/td&gt; &lt;td&gt;@row3.Firm_Name&lt;/td&gt; &lt;td style="text-align:center"&gt;&lt;a href="http://@row3.Website"&gt;@row3.Website&lt;/a&gt;&lt;/td&gt; &lt;td style="text-align:center"&gt;@row3.Phone_Office&lt;/td&gt; &lt;td style="text-align:center"&gt;@row3.City_Phys&lt;/td&gt; &lt;/tr&gt; } } else { foreach (var row4 in db.Query(querypeople + where + city + selectedlocat + app + and + field + selectedfield + app + order)) { &lt;tr&gt; &lt;td style="text-align:center; width: 110px"&gt;@row4.Last_Name, @row4.First_Name &lt;/td&gt; &lt;td&gt;@row4.Firm_Name&lt;/td&gt; &lt;td style="text-align:center"&gt;&lt;a href="http://@row4.Website"&gt;@row4.Website&lt;/a&gt;&lt;/td&gt; &lt;td style="text-align:center"&gt;@row4.Phone_Office&lt;/td&gt; &lt;td style="text-align:center"&gt;@row4.City_Phys&lt;/td&gt; &lt;/tr&gt; } } } } &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p></p> <p>I hope this gives a little better idea of what I am trying to do here.</p> <p>*<strong><em>EDIT</em>*</strong></p> <p><strong>So I can better form my future questions, why did you downvote this one?</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload