【发布时间】:2016-04-27 10:26:57
【问题描述】:
我有两个文本框和一个下拉列表。我已经通过 Ajax.BeginForm() 方法使用它们的 id 将文本框的值传递给控制器操作方法。但是如何传递下拉列表的值,因为它没有由 id 定义。这是我的代码:
DeliveryIndex.cshtml:
@using (Ajax.BeginForm("CustomerFilter", "Delivery", new System.Web.Mvc.Ajax.AjaxOptions
{
InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace,
HttpMethod = "POST",
UpdateTargetId = "deliverylist"
}))
{
<input id="from" name="from" type="text" />
<input id="to" name="to" type="text" />
@Html.DropDownList("CUS_NAME",null,"--Select Customer--",new { @Style = "WIDTH:169PX" })
<input type="submit" value="View" id="BtnSubmit" />
}
控制器:
public class DeliveryController : MasterController
{
public ActionResult DeliveryIndex()
{
ViewBag.CUS_NAME = new SelectList(db.CUSTOMER_MASTER.ToList().OrderBy(c => c.CUS_NAME), "CUS_NAME", "CUS_NAME");
return View("DeliveryIndex");
}
[HttpPost]
public ActionResult CustomerFilter(string from, string to, string )
{
....
}
}
【问题讨论】:
-
您似乎还没有将其绑定到模型。使用 DropDownListFor 并将其绑定到模型。您选择的值将在您的模型中可用。
标签: c# asp.net ajax asp.net-mvc asp.net-mvc-4