[CLOSED] Ajax Linked Combobox SetValue()
I take an example of ajax linked combo in MVC Razor.No problem in Load but when I set value click on Set button,both city and country field get blank.
may be I am doing some mistake,please suggest me how do I do this.
View
Code:
@model System.Collections.IEnumerable
@Html.X().ResourceManager()
@(Html.X().FormPanel().ID("f").Items
(
Html.X().ComboBox()
.ID("ComboBoxCountry")
.Editable(false)
.QueryMode(DataLoadMode.Local)
.TriggerAction(TriggerAction.All)
.EmptyText("Select a country")
.DisplayField("Name")
.ValueField("Id")
.FieldLabel("Country")
.ForceSelection(true)
.Listeners(ls =>
{
ls.Select.Handler = "App.ComboBoxCity.clearValue(); App.ComboBoxCity.getStore().load()";
})
.Store(Html.X().Store()
.Model(Html.X().Model()
.IDProperty("Id")
.Fields(
Html.X().ModelField().Name("Id").Type(ModelFieldType.String),
Html.X().ModelField().Name("Name").Type(ModelFieldType.String)
)
)
.DataSource(ViewBag.country)
)
,
Html.X().ComboBox()
.ID("ComboBoxCity")
.TypeAhead(true)
.QueryMode(DataLoadMode.Local)
.ForceSelection(true)
.FieldLabel("City")
.TriggerAction(TriggerAction.All)
.DisplayField("name")
.ValueField("id")
.EmptyText("Loading...")
.ValueNotFoundText("Loading...")
.Store(Html.X().Store()
.AutoLoad(false)
.Model(Html.X().Model()
.IDProperty("Id")
.Fields(
new ModelField("id", ModelFieldType.String) { Mapping = "Id" },
new ModelField("name", ModelFieldType.String) { Mapping = "Name" }
)
)
.Proxy(Html.X().AjaxProxy()
.Url(Url.Action("GetCities"))
.Reader(Html.X().JsonReader().Root("data"))
)
.Parameters(ps =>
ps.Add(new StoreParameter("country", "App.ComboBoxCountry.getValue()", ParameterMode.Raw))
)
.Listeners(ls =>
ls.Load.Handler = @"var combo = App.ComboBoxCity;
combo.setValue(records[0].get(combo.valueField));"
)
)
)
.Buttons
(
Html.X().Button().Text("set")
.DirectEvents(de =>
{
de.Click.FormID = "f";
de.Click.Action = "set";
})
)
)
CONTROLLER
Code:
public ActionResult Index()
{
loadcountry();
return View();
}
public ActionResult GetCities(string country)
{
return this.Store(Cities(country));
}
public void loadcountry()
{
List<object> country = new List<object>(10);
country.Add(new { Id = 1, Name = " Country 1" });
country.Add(new { Id = 2, Name = " Country 2" });
ViewBag.country = country;
}
public object Cities(string country)
{
List<object> cities = new List<object>(10);
for (int i = 1; i <= 10; i++)
{
cities.Add(new { Id = i.ToString() + i,Name= i.ToString()+" City of "+country });
}
return cities;
}
public DirectResult set()
{
X.GetCmp<ComboBox>("ComboBoxCountry").SetValue(1);
X.GetCmp<ComboBox>("ComboBoxCity").SetValue(1);
return this.Direct();
}