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

[Solved] Multple dropdown's with the same name

1 Answer 80 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.
Shrinath
Top achievements
Rank 1
Shrinath asked on 19 Jan 2012, 11:39 PM
Hello,

I have an array of InsuranceModel and I have a jquery tab that displays the data for each of these in the array. So each tab lists the same Insurance object on each tab and there is a drop down, the same exact drop down. I'm able to bind everything fine except for the Telerik Drop Down and Telerik Calendar. On the first tab the drop down works but on other tabs the drop down doesn't go down. In the controller the value for what the drop down is supposed to return is null. The Telerik dropdown REQUIRES a name that is a string and I can't specifically bind it to one of the elements in the array like a normal control. How can I provide the correct "Name"?

Here is some sample code:

Drop down on view:
@(Html.Telerik()
    .DropDownList()
    .Name("Type")
    .BindTo(Model[myCounter].Types)
    .HtmlAttributes(new { style = "width:220px" })
    .Value(Model[myCounter].Type)
)
Normal control on view that works:
                                                    @Html.TextBoxFor(model => model[myCounter].PayerCode, new { maxlength = 50 })
                                                    @Html.ValidationMessageFor(model => model[myCounter].PayerCode)


Controller accepting the model on post:
  [HttpPost]
 [ExportModelStateToTempData]
 public ActionResult Create(ICollection<InsuranceModel> aModel) {
//code
}


1 Answer, 1 is accepted

Sort by
0
Shrinath
Top achievements
Rank 1
answered on 19 Jan 2012, 11:45 PM
I actually just figured out a solution, but maybe there is a better one but here's what works now:

@(Html.Telerik()
    .DropDownList()
    .Name("[" + myCounter + "].Type")
    .BindTo(Model[myCounter].Types)
    .HtmlAttributes(new { style = "width:220px" })
    .Value(Model[myCounter].Type)
)
Tags
ComboBox
Asked by
Shrinath
Top achievements
Rank 1
Answers by
Shrinath
Top achievements
Rank 1
Share this question
or