控制器:
public ActionResult ComboBox()
{
List<ComboBoxClass> Products = new List<ComboBoxClass>();
Products.Add(new ComboBoxClass { ProductName = "Masa" });
Products.Add(new ComboBoxClass { ProductName = "Sandalye" });
Products.Add(new ComboBoxClass { ProductName = "Bilgisayar" });
Products.Add(new ComboBoxClass { ProductName = "Laptop" });
Products.Add(new ComboBoxClass { ProductName = "Kulaklık" });
Products.Add(new ComboBoxClass { ProductName = "Bardak" });
Products.Add(new ComboBoxClass { ProductName = "Kalem" });
Products.Add(new ComboBoxClass { ProductName = "Seramik" });
Products.Add(new ComboBoxClass { ProductName = "Telefon" });
ViewData["Products"] = Products;
return View(Products);
}
查看:
@Html.DevExpress().ComboBox(
settings =>
{
settings.Name = "BenimComboBox";
settings.Width = 180;
settings.Properties.ValueField = "ProductName";
settings.SelectedIndex = -1;
settings.Properties.IncrementalFilteringMode = IncrementalFilteringMode.StartsWith;
settings.Properties.DropDownStyle = DropDownStyle.DropDown;
settings.Properties.TextField = "ProductName";
settings.Properties.ValueField = "ProductName";
}
).BindList(ViewData["Products"]).GetHtml()
类
public class ComboBoxClass
{
public string ProductName { get; set; }
}
我有产品。我列出了ComboBox上的所有产品。如何将我的SelectedIndexChanged值传递给ActionResult?
我希望在“string SelectedItem”
下面看到所选值public ActionResult SelectedItemHere(string SelectedItem)
{
// Processes..
return View();
}
答案 0 :(得分:4)
您需要将以下代码添加到Combobox中,
settings.Properties.ClientSideEvents.SelectedIndexChanged = "SelectedId";
之后
布局中的Javascript代码
function SelectedId() {
var data= {
SelectedItem: BenimComboBox.GetValue(),
};
$.ajax({
url: "/YOUR CONTROLLER/YOUR ACTİONRESULT",
type: "POST",
dataType: "json",
contentType: 'application/json',
data: JSON.stringify(data),
最后,
控制器:
public ActionResult SelectedItemHere(string SelectedItem)
{
// Processes..
return View();
}
答案 1 :(得分:0)
按客户端访问DevExpress ComboBox选择索引
function OnComboBoxSelectedIndexChanged(e, s) {
//check seleted index
var selected_index = e.lastSuccessValue;
alert(selected_index);
}
<dx:ASPxComboBox ID="cbsample" runat="server" AutoPostBack="true">
<ClientSideEvents SelectedIndexChanged="OnComboBoxSelectedIndexChanged" />
<Items>
<dx:ListEditItem Text="item name" Value="0" />
<dx:ListEditItem Text="item name1" Value="1" />
<dx:ListEditItem Text="item name2" Value="2" />
</Items>
</dx:ASPxComboBox>