Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I bind data from Telerik ComboBox to my data model

Why won't my Telerik ComboBoxFor bind my value and fill my ComboBox via AJAX?

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
    <div class="editor-field">
        @Html.EditorFor(model => model.Name)
        @Html.ValidationMessageFor(model => model.Name)
    </div>
    <div class="editor-field">
    @(Html.Telerik().ComboBoxFor(model => model.VendorId)
        .Name("ddlVendor")
        .ClientEvents(events =>
                          {
                              events.OnLoad("onVendorLoad");
                              //events.OnChange("onVendorChange");
                              events.OnDataBinding("onComboBoxDataBinding");
                          }
        )
        .DataBinding(bind => bind.Ajax().Select("_AjaxGetVendors", "Car"))
    )
    </div>
    <p>
        <input type="submit" value="Зберегти" />
    </p>
</fieldset>}

In my controller I get entity but VendorId == 0.

 [HttpPost]
    public ActionResult Create(Car obj)
    {
            dm.InsertModel(obj);
            return RedirectToAction("Create");
    }
like image 556
user571874 Avatar asked Feb 06 '12 08:02

user571874


1 Answers

Option 1

Remove .Name("ddlVendor") from your ComboBox if you don't need it.

Option 2

Rename your ComboBox as follows and update any client event references to the control:

.Name("VendorId") 
like image 135
Nick Avatar answered Nov 04 '22 18:11

Nick