在 Html(我没有使用)中
<select>
<option value="B">Bubblegum</option>
</select>
在(来自控制器)Aspx 中
[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);
}
然后在视图中:
<% 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" })%>
如何在 aspx 引擎中获取 Html.DropDownListFor 的选定值“B”,以便我将其作为字符串发送到数据库中?