In Html (which I did not use) it’s
<select>
<option value="B">Bubblegum</option>
</select>
In (from controller) Aspx it’s
[HttpGet]
public ActionResult ViewMethod()
{
//Populate DropDownList
Treats = new List<KeyValuePair<string, string>>();
Treats.Add(new KeyValuePair<string, string>("Bubblegum", "B"));
ViewData["treats"] = new SelectList(Treats, "Value", "Key", SelectedTreat);
return View();
}
[HttpPost]
public ActionResult GeneratedContent(SomeModel model)
{
List<HalloweenTreats> ChewingGums = StoredProc(model.SelectedTreat);
return PartialView(ChewingGums);
}
then in the View:
<% using (Ajax.BeginForm("ViewMethod", "ControllerName", new AjaxOptions { UpdateTargetId = "DisplayValues" })) { %>
<%: Html.DropDownListFor(x => x.SelectedTreat, ViewData["treats"] as SelectList)%>
<input type = 'submit' name = 'submit' value = 'generate' />
<div id="DisplayValues"></div>
<% } %>
<%: Ajax.ActionLink("Generate", "RequestReportSummary", "Report", new { model = Model }, new AjaxOptions { UpdateTargetId = "GeneratedReport" })%>
How to get the selected value “B” of Html.DropDownListFor in aspx engine for me to send it as a string in the database?
The controller action you are posting to could take your model as parameter: