具有id和值的关系表的kendo组合样本

时间:2013-11-04 17:12:40

标签: asp.net-mvc-4 combobox kendo-asp.net-mvc

我在我的asp.net mvc 4中使用了kendo ui和razor视图,并且当列表从动作通过ajax加载并通过发送参数到服务器时遇到kendo组合问题:HERE  因为这个表有超过2000行。

当我加载编辑页面时,组合加载并按预期过滤数据,但该字段的值为 - [object object]。

我确实声明了.DataTextField(“ProffName”)+ .DataValueField(“ID”)

My ClientsController:

public ActionResult Edit(int id = 0)
    {
        Clients clients = db.Clients.Find(id);
        if (clients == null)
        {
            return HttpNotFound();
        }
        ViewData["MyAgency"] = new SelectList(db.Agency, "ID", "AgentName", clients.AgencyId);
        ViewData["MyCategory1"] = new SelectList(db.CategoryTbl, "ID", "category", clients.CategoryId);

        List<SelectListItem> obj = new List<SelectListItem>();
        obj.Add(new SelectListItem { Text = "male", Value = "1" });
        obj.Add(new SelectListItem { Text = "female", Value = "2" });
        obj.Add(new SelectListItem { Text = "choose", Value = "0" });
        ViewData["MyMin"] = obj;

        ViewBag.ProffID = new SelectList(db.ProfTBL, "ID", "ProffName", clients.ProffID);
        ViewBag.Metapel = new SelectList(db.Workers, "ID", "WorkerName", clients.Metapel);
        return View(clients);
    }

我的ProffController:

public ActionResult ProffVM_Read(string text)
    {
        var Proff_Tbl = db.ProfTBL.Select(proff => new ProffVm { ID = proff.ID, ProffName = proff.ProffName });
        if (!string.IsNullOrEmpty(text))
        {
            Proff_Tbl = Proff_Tbl.Where(p => p.ProffName.Contains(text));
        }
        return Json(Proff_Tbl, JsonRequestBehavior.AllowGet);
    }

和剑道组合:

@Html.Label("Proff")
                            @(Html.Kendo().ComboBoxFor(model => model.ProffID)
                              .Name("proffCbo")
                              .DataTextField("ProffName")
                              .DataValueField("ID")
                              .Events(e => e
                                    .Select("proffCbo_select")
                                    .Change("proffCbo_change")
                                )
                              .DataSource(source =>
                              {
                                  source.Read(read =>
                                  {
                                      read.Action("ProffVM_Read", "Proff")
                                               .Data("onAdditionalData");
                                  });
                              })
                            )
我错了吗? 我可以将这个组合改为文本框,但是......我必须意识到这一点。

由于

1 个答案:

答案 0 :(得分:0)

更改这两行

var Proff_Tbl = db.ProfTBL.Select(proff => new ProffVm { ID = proff.ID, ProffName = proff.ProffName });

Proff_Tbl = Proff_Tbl.Where(p => p.ProffName.Contains(text));

var Proff_Tbl = db.ProfTBL.Select(proff => new ProffVm { ID = proff.ID, ProffName = proff.ProffName }).ToList();

Proff_Tbl = Proff_Tbl.Where(p => p.ProffName.Contains(text)).ToList();