问题描述
// 1。页面加载时,所有产品ID绑定到下拉列表。当用户从下拉列表中选择产品ID并单击添加按钮时,相应的产品详细信息将添加到网格中,同一产品ID将从下拉列表中删除。
// 2。当用户从网格中删除产品时(通过使用删除链接),相应的产品ID将添加回下拉列表。**
公共类ProductModel
{
公开列表< long>产品{得到;组; } //产品ID列表 - 绑定到kendo下拉列表
public List< products>产品{get;组; } //产品列表绑定到剑道网格
}
公共类ProductController:Controller
{
// **控制器:**
public JsonResult RefreshDatata(long Id)
{
var model = new ProductModel();
_prodIds = model.ProdIds.add(id);
_products = model.Products.Removeat(Products。 FirstOrDefault(x => x.ProductId == id))
返回Json(新{ProdIds = _prodIds,Products = _Prodcusts},JsonBehaviour.AllowGet()) ;
}
}
// **查看(。 cshtml)**
$ .ajax({
类型:POST,
url:RefreshDatata / Product,
数据:
{
id:id,
},
成功:函数(结果)
{
// ** //如何绑定kendo网格并从json结果刷新(_products)**
// ** //如何绑定dropdownlist并刷新json结果(_ProductIds)**
}
});
//1. when page load, all products ids bind to dropdownlist. when user select a product id from dropdownlist and click on Add button then corresponding product details would add to grid and same product id delete from the dropdown list.
//2. When user remove a product from grid (by using remove link) then corresponding product id would added back to dropdownlist.**
public class ProductModel
{
public List<long> ProdIds { get; set; } //list of product id's - bind to kendo dropdownlist
public List<products> Products { get; set; }//list of products bind to kendo grid
}
public class ProductController : Controller
{
// **Controller:**
public JsonResult RefreshDatata(long Id)
{
var model = new ProductModel();
_prodIds = model.ProdIds.add(id);
_products = model.Products.Removeat(Products.FirstOrDefault(x=>x.ProductId==id))
return Json(new {ProdIds=_prodIds ,Products=_Prodcusts},JsonBehaviour.AllowGet());
}
}
// **View(.cshtml)**
$.ajax({
type: "POST",
url: "RefreshDatata/Product",
data:
{
id: id,
},
success: function(result)
{
// **//how to bind kendo grid and refresh from json result (_products)**
// **//how to bind dropdownlist and refresh from json result (_ProductIds)**
}
});
推荐答案
这篇关于Kendo下拉列表和kendo网格绑定并使用json刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!