1

I gave a Devexpress GridView which represent addresses. Two cascading combobox (Governorate- Area). When the user choose a Governorate the area combo will filtered according to the Governorate chased. When the user doesn't know the corresponding Governorate for the area, he only start by choosing the area and the governorate combobox will fill with the right governorate.

In index.chtml

<script type="text/javascript">
function governorateCombo_SelectedIndexChanged(s, e) {
    areaCode.PerformCallback();
}
function AreaCombo_BeginCallback(s, e) {
    e.customArgs['governorateCode'] = governorateCode.GetValue();
}

function areaCombo_SelectedIndexChanged(s, e) {
    governorateCode.PerformCallback();
}
function GovernorateCombo_BeginCallback(s, e) {
    e.customArgs['areaCode'] = areaCode.GetValue();
}

function GovernorateCombo_EndCallback(s, e) {
    benGeoGridView.Refresh();
    var bla = '@Session["governorateCode"]';
    var item = s.FindItemByValue(bla);
    s.SetSelectedItem(item);
}

ComboboxGovernoratePartial.chtml

@Html.DevExpress().ComboBox(settings =>
{
settings.CallbackRouteValues = new { Controller = "benFile", Action = "ComboBoxGovernoratePartial" };
settings.Name = "governorateCode";
settings.Properties.TextField = "governorateName1";
settings.Properties.ValueField = "governorateCode";
settings.Properties.ValueType = typeof(string);
settings.Width = 220;
settings.Properties.EnableSynchronization = DefaultBoolean.False;
settings.Properties.IncrementalFilteringMode = IncrementalFilteringMode.StartsWith;
if (Thread.CurrentThread.CurrentCulture.Name.Substring(0, 2) == "ar")
{
    settings.RightToLeft = DefaultBoolean.True;
}
settings.Properties.ClientSideEvents.BeginCallback = "GovernorateCombo_BeginCallback";
settings.Properties.ClientSideEvents.SelectedIndexChanged = "governorateCombo_SelectedIndexChanged";
settings.Properties.ClientSideEvents.EndCallback = "GovernorateCombo_EndCallback";
}).BindList(Model).Bind(ViewData["governorateCode"]).GetHtml()

In controller:

 public ActionResult ComboBoxGovernoratePartial()
    {
        string areaCode = (Request.Params["areaCode"] != null) ? Request.Params["areaCode"] : "-1";

        List<governorateName> governorateNames = new List<governorateName>();

            governorateMaster governorateMaster = new governorateMaster();

            if (areaCode != null)
            {
                Session["governorateCode"] = Masters.areaMasters.First(a => a.areaCode == areaCode).governorateCode; ;
                ViewData["governorateCode"] = Masters.areaMasters.First(a => a.areaCode == areaCode).governorateCode;
                governorateNames = Masters.governorateNames.Where(a => a.langCode.ToLower() == Thread.CurrentThread.CurrentCulture.Name.Substring(0, 2)).ToList();
            }
       return PartialView(governorateNames.ToList());
    }

When the user choose the area, (in js) I call perform call back for the governorate combobox that the controller pick up the right governorate to populate in the governorate combobox. The problem is that when I send the governorate code in a ViewData it is always null. In a Session varible, the value of it is the one at page load not the updated one in the controller.

Any suggestion ?

Sorry for your time guys

1
  • Why don't you contact the DevExpress support channel directly?
    – Mikhail
    Dec 3, 2013 at 17:41

1 Answer 1

0

For that, you can try:

TempData["yourVar"]
1
  • 2
    Welcome to Stack Overflow! Could you please edit in an explanation of why this is a good answer?
    – Scimonster
    Feb 5, 2015 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.