user571874
user571874

Reputation: 589

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");
    }

Upvotes: 5

Views: 2336

Answers (1)

Nick
Nick

Reputation: 5872

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") 

Upvotes: 5

Related Questions