Daniel

Is the combobox posted with a form? If yes, then you should bind the combobox to the Part.Id property:

Html.Kendo().ComboBoxFor(model => model.Part.Id)

Regards,
Daniel
Telerik

Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items

Daniel

The custom value will be sent to the server but in most cases it will not be bound by the model binder. If custom values should be allowed then you could retrieve it from the ModelState or from the request data:

if (ModelState["Part.Id"].Errors.Any())

{

var customValue = ModelState["Part.Id"].Value.AttemptedValue;

ModelState.Remove("Part.Id");

AddCustomValue(customValue);

}

Regards,
Daniel
Telerik

Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items

That works until I enter a new custom value in the ComboBox. The ComboBox shows the value, but once I leave Edit mode for the cell, the grid shows "undefined" for the value. How do I get it showing the new value?

Daniel

If the same editor is used for a grid then I can suggest either to use a ForeignKey column for the Part.Id field or bind the column to the object and explicitly specify the binding in the editor via the HtmlAttributes method:

columns.Bound(p => p.Part)

Html.Kendo().ComboBoxFor(model => model.Part.Id)

.HtmlAttributes(new { data_bind = "value:Part"})

...

This way the Id field will be posted correctly with the form but the object will be bound when using the editor for the grid. Using a separate editor for the grid is another option.

Regards,
Daniel
Telerik

Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items

Daniel

I am not sure if i understand correctly the issue but if you wish to submit the grid data with a form as part of the assembly then you can use the approach demonstrated in this code-library project.

Regards,
Daniel
Telerik

Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items

Daniel

It seems the approach with explicitly specifying the binding will not work for the combobox. Because of the name generated for the text input the correctly bound object will be overridden. In that case I can suggest to use a separate editor for the grid or to remove the text input name via code or to use a foreignkey column. I attached a sample project that demonstrates the suggested solutions.

Regards,
Daniel
Telerik

Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items

Daniel

The foreignkey column cannot be used for custom values because it can only show values available in the data that is passed initially on the server. The problem with displaying the value when binding to object can be avoided by changing the logic in the template but the binding will not work correctly after setting a custom value because the field will no longed be an object. Custom binding might be the best option for this scenario. I attached the project modified to demonstrate one possible implementation.

Regards,
Daniel
Telerik

Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items

Bill Wingate

The last piece is that I need to do server filtering for the combo box data source, based on the entered text. I previously had this working, but since I adapted to use your code it's not. What is the id of the combo box now?

I have this for the data source:

source.Read(read =>

{

read.Action("GetParts", "Home").Data(@<text>

function()

{

var val=$("#Part").data("kendoComboBox").input.val();

return {

userId: @ViewBag.UserId,

Name: val}

}

But using "#Part" doesn't work. How do I get the current value of the combobox?

Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.