问题描述:

I created this sample locally

http://demos.telerik.com/kendo-ui/mvvm/remote-binding

In my 'update' transport, I did modify the 'ProductName' from my WebAPI

 public IHttpActionResult Update(Product prod)

{

prod.Price = prod.UnitPrice * prod.Quantity;

prod.ProductName = prod.ProductName + DateTime.Now.ToString();

return Ok(prod);

}

It did update and reflect on my 'dropdownlist'.

The issue is the textbox id=products is not showing the latest productname. The textbox is binded using

data-bind="value: selectedProduct.ProductName"

How can I refresh this text box ?

Thank you.

All is same except this

 update: {

url: "/Product/Update",

contentType: "application/json",

type: "POST"

},

and this.

 parameterMap: function (data, type) {

return kendo.stringify(data);

}

If these changes are not made; my webapi will not receive any value.

  • I notice like the binding somehow got broken momentarily; is it because its indirectly reference using the var 'selectedProduct' ?

网友答案:

The reason, I believe, that your textbox is not updating is because of two reasons: 1) you're changing the data on the server instead of the client, and 2) the textbox is tied to the selectedProduct variable which is in no way tied to the data source.

In other words, when you submit the update, because your dropdown list is bound to the productSource data source, it's data gets updated automatically and the list is refreshed to show you the changes. This is expected. On the other hand, selectedProduct is not tied to the data source in any way, so, it still holds the old value before the update was called.

The solution is you have to manually update selectedProduct after the update request returns.

相关阅读:
Top