Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to keep the value of a dropdown selected after post (razor)
    text
    copied!<p>I have this dropdown in my form and it shows a list of names called from a database. Whenever I select one and submit the form the page refreshes to show the results and the selected value goes back to blank. Is there a way to keep the selected value after I post the form?</p> <pre><code> &lt;li class="form-line form-line-column" id="id_22"&gt; &lt;label class="form-label-top" id="label_22" for="input_22"&gt; ADMIN &lt;/label&gt; &lt;div id="cid_22" class="form-input-wide"&gt; &lt;select name="formAssigned_To"&gt; &lt;option&gt;&lt;/option&gt; @foreach(var row in db.Query("SELECT DISTINCT Name FROM Admins")){ &lt;option value="@row.Name"&gt;@row.Name&lt;/option&gt; } &lt;/select&gt; &lt;/div&gt; &lt;/li&gt; </code></pre> <p>I have this other dropdown in the same form and this one is static so its not being called from a database and the selected value stays. However, I cannot do the same with the first dropdown, any ideas as to why?</p> <pre><code> &lt;li class="form-line form-line-column" id="id_22"&gt; &lt;label class="form-label-top" id="label_22" for="input_22"&gt; Status &lt;/label&gt; &lt;div id="cid_22" class="form-input-wide"&gt; &lt;select class="form-dropdown" style="width:75px" id="input_22" name="formCase_Status"&gt; &lt;option selected="@(Request["formCase_Status"])"&gt;&lt;/option&gt; &lt;option selected="@(Request["formCase_Status"] == "In Progress")" value="In Progress"&gt; In Progress &lt;/option&gt; &lt;option selected="@(Request["formCase_Status"] == "Pending")" value="Pending"&gt; Pending &lt;/option&gt; &lt;option selected="@(Request["formCase_Status"] == "Closed")" value="Closed"&gt; Closed &lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;/li&gt; </code></pre>
 

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