Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing AJAX to return SelectList selected value
    primarykey
    data
    text
    <p>At risk of asking the obvious... I need to use AJax.ActionLink to send the current value of a SelectList back to my controller. How do I do that?</p> <p>Below is part of my current View. I need to replace "15" with the current value of the SelectList.</p> <pre><code>&lt;% If Model.ShoppingListNames IsNot Nothing Then%&gt; &lt;%: Html.DropDownList("ShoppingListNames", Model.ShoppingListNames)%&gt; &lt;%: Ajax.ActionLink("Add to List", "AdjustMaterials", "Docs", New With {.userDocId = 15, .prodId = Model.ID, .quantity = 1}, New AjaxOptions With {.OnSuccess = "handleUpdate"})%&gt; &lt;% End If%&gt; </code></pre> <p>Using the "answer" to use Ajax.BeginForm instead of Ajax.ActionLink, below is part of the View I ended up with.</p> <pre><code> &lt;% If Model.ShoppingListNames IsNot Nothing Then%&gt; &lt;% Using Ajax.BeginForm("AdjustMaterials", "Docs", New With {.prodId = Model.ID}, New AjaxOptions With {.UpdateTargetId = "result-message"})%&gt; &lt;%: Html.DropDownList("userDocId", Model.ShoppingListNames)%&gt; &lt;input value ="Add to List" type ="submit"/&gt; &lt;% End Using%&gt; &lt;div id="result-message"&gt;&lt;/div&gt; &lt;% End If%&gt; </code></pre> <p>And below is the controller. Note that the prodId parameter is specified in the call to Ajax.BeginForm but the userDocId parameter is specified by the current value of the SelectList within the form.</p> <pre><code>&lt;HttpPost()&gt; Function AdjustMaterials(ByVal userDocId As Integer, ByVal prodId As Integer, Optional ByVal quantity As Integer = 1, Optional ByVal itemTag As String = Nothing) As ActionResult ' Do stuff... End Function </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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