2013-07-27 105 views
1

控制器:DevExpress的組合框在asp.net MVC的SelectedIndexChanged

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; } 
    } 

我products.I列表上的所有產品ComboBox.How能我將我的SelectedIndexChanged值傳遞給ActionResult?

我想看看下面的 「字符串的SelectedItem」

public ActionResult SelectedItemHere(string SelectedItem) 
{ 
// Processes.. 
return View(); 
} 

回答

4

您需要將下面的代碼添加到您的組合框選擇的值,

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(); 
} 
+0

Workes完美,除了我不得不做一個小的變化。發佈它以防萬一其他用戶無法運行該功能。 settings.Properties.ClientSideEvents.SelectedIndexChanged =「function(s,e){getData()}」; – nishantvodoo

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>

相關問題