2

在 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”,以便我将其作为字符串发送到数据库中?

4

1 回答 1

1

您发布到的控制器操作可以将您的模型作为参数:

[HttpPost]
public ActionResult ViewMethod(SomeModel model)
{
    // model.SelectedTreat will contain the selected value here
}
于 2012-08-19T06:39:29.850 回答