Reputation: 71
Controller:
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);
}
View:
@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()
Class
public class ComboBoxClass
{
public string ProductName { get; set; }
}
I have products.I list all products on ComboBox.How can ı pass my SelectedIndexChanged value to ActionResult ?
I want to see selected value below " string SelectedItem "
public ActionResult SelectedItemHere(string SelectedItem)
{
// Processes..
return View();
}
Upvotes: 2
Views: 10682
Reputation: 2965
Access DevExpress ComboBox Selected Index by client side
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>
Upvotes: 0
Reputation: 400
You need to add below code to your Combobox,
settings.Properties.ClientSideEvents.SelectedIndexChanged = "SelectedId";
After that
Javascript Code in your layout
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),
And Last,
Controller:
public ActionResult SelectedItemHere(string SelectedItem)
{
// Processes..
return View();
}
Upvotes: 5