This is a migrated thread and some comments may be shown as answers.

[Solved] DropDownFor - CascadeTo without .Name

3 Answers 111 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marta
Top achievements
Rank 1
Marta asked on 03 Apr 2012, 06:59 AM
Hi,

Seems that when I'm using DropDownListFor() and would like to bind it to model I had to remove .Name like in this post 
http://www.telerik.com/community/forums/aspnet-mvc/combobox/comboboxfor-model-binding.aspx
" .Name("EmployeeIdComboBox")
and now it works! ".

Problem is that I was also using CascadeTo in this DropDown and it doesn't work without .Name. Do you know workaround how can I still use CasdadeTo without .Name?

3 Answers, 1 is accepted

Sort by
0
Martin
Top achievements
Rank 1
answered on 04 Apr 2012, 07:48 AM
Hi,

I have this code and its works
@(Html.Telerik().ComboBoxFor(model => model.Combo1)
.AutoFill(true)
.Placeholder("Choose")
.CascadeTo(ViewData.TemplateInfo.HtmlFieldPrefix.HtmlConvertNameToId() + "_Combo2")
.DataBinding(binding => binding.Ajax().Select("LoadCombo1", "List"))
.Filterable(filtering =>
{
filtering.MinimumChars(3);
filtering.FilterMode(AutoCompleteFilterMode.Contains);
})
.HighlightFirstMatch(true))
@(Html.Telerik().ComboBoxFor(model => model.Combo2)
.AutoFill(true)
.HiddenInputHtmlAttributes(new { @id = ViewData.TemplateInfo.HtmlFieldPrefix.HtmlConvertNameToId() + "_Combo2" })
.DataBinding(binding => binding.Ajax().Select("LoadCombo2", "List"))
.Filterable(filtering =>
{
filtering.MinimumChars(3);
filtering.FilterMode(AutoCompleteFilterMode.Contains);
})
.HighlightFirstMatch(true))

where HtmlConvertNameToId replace '[',']','.' to '_' because jQuery cannot works with this chars in searching criteria. But I Have different problem because CascadeTo doesn't work without specifying Placeholder

Regards

Martin
0
Marta
Top achievements
Rank 1
answered on 05 Apr 2012, 09:28 AM
Hi Martin,

Thanks for your answer.
I have one question regarding your code, when you have method "LoadCombo2"  in controller how you get what value was selected in Combo1?

As I know the name of parameter in LoadCombo2 should be name of Combo1 like LoadCombo2(int? combo1name), because we ship .Name name of Combo1 it is with dot and it can't be a parameter in C# code.
 
Thanks,
Marta
0
Martin
Top achievements
Rank 1
answered on 20 Apr 2012, 06:34 AM
Hi,

sorry for late reply.

I don't have explicit parameter in controller action. Its because I have multiple combo pairs on one page witch is in List of my view object. Than because i cannot specify binding prefix in code I iterate Request.Form

Something like this
[HttpPost]
        public ActionResult LoadCombo2(string text)
        {
            foreach (var key in Request.Form.AllKeys)
            {
                long combo1Id;
                if (key.EndsWith("combo1Id") && long.TryParse(Request.Form[key], out combo1Id))
                {
                    var list = SearchById(combo1Id)                   
                    return new JsonResult { Data = new SelectList(cpvList, "Id", "Name") };
                }
            }
            if (!String.IsNullOrEmpty(text))
            {
                var list = Search(text);
                return new JsonResult { Data = new SelectList(list, "Id", "Name") };
            }
            return new JsonResult { Data = new SelectList(new List<Foo>() { new Foo{ Id = 0, Name = "" } }, "Id", "Name") };
        }


Matin
 
Tags
ComboBox
Asked by
Marta
Top achievements
Rank 1
Answers by
Martin
Top achievements
Rank 1
Marta
Top achievements
Rank 1
Share this question
or