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

No data being posted

2 Answers 143 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 1
Allan asked on 18 Nov 2015, 11:44 AM

Hi there,

My form has a combo box that is populated from a viewbag in a controller.  The Combobox isn't posting any data when the form is submitted however.  I don't get any errors but the values in the database are always null.  What have I done wrong?

 The Combobox Code

 

@(Html.Kendo().ComboBox()
      .Name("workscopecode")
      .DataTextField("Text")
      .DataValueField("workscopecode")                      
      .Filter(FilterType.Contains)
      .Placeholder("-- Select Duties --")
      .BindTo(ViewBag.duties))

 My Viewbag in my Controller Code

IEnumerable<SelectListItem> duties = mydata.tbl_workscopes
 
    .Select(c => new SelectListItem
    {
        Value = c.idx_index.ToString(),
        Text = c.code
    });
ViewBag.duties = duties;

2 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 20 Nov 2015, 08:53 AM
Hello Allan,

The ComboBox widget has an input element with a name attribute equal to the Name specified in the widget's configuration. Basically, posting the form should include that input element, however it might not be bound on the server in case the Model has no field with matching name. You can check the browser's network tab and verify what is being posted. If that is indeed the case, then I would suggest either set a matching name or use the ComboBoxFor helper instead (without explicitly specifying the name). For example: 
@(Html.Kendo().ComboBoxFor(m=>m.SomeModelField) ... )

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
CIQIntegration
Top achievements
Rank 1
answered on 02 Dec 2015, 09:31 AM

Hi Allan,

i dont know if you still got this issue.

keep in mind you'll need to add the deferred option on the combobox - like so:

@(Html.Kendo().ComboBoxFor(m => m.Contract.ContractName)
                                           .Name("ContractSelection")
                                           .HtmlAttributes(new { @class = "form-control", style = "width:100%" })
                                           .DataValueField("Id")
                                           .DataTextField("Text")
                                           .AutoBind(false)
                                           .Deferred()
                                           .DataSource(s =>
                                           {
                                               s.Read(r =>
                                               {
                                                   r.Action(MVC.Contract.ActionNames.LookupList, MVC.Contract.Name);
                                               })
                                               .ServerFiltering(true);
                                           })                                 
                                   )

 

hopte this helps

 

Tags
ComboBox
Asked by
Allan
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
CIQIntegration
Top achievements
Rank 1
Share this question
or