2013-05-22 39 views
1

sir任何人都可以借我一把手来修复我的程序..即时通讯使用kendo ui在我的asp.net mvc。问题是数据库中的记录没有显示每次运行程序时它只显示nothing.and表明错误..说“{”实体或复杂类型'database.APPLICANT'不能在LINQ to Entities中构建。查询 “}”asp.net使用mvc 3申请kendo ui

这里是我的控制器:

private IQueryable<APPLICANT> GetApplicant() 
    { 
     var applicants = (from a in dbContext.APPLICANTs 
          select a).Take(50).ToList(); 

     return applicants as IQueryable<APPLICANT>; 
    } 

    public ActionResult GetApplicant([DataSourceRequest] DataSourceRequest request) 
    { 
     return Json(GetApplicant().ToDataSourceResult(request)); 
    } 

    public ActionResult UpdateCustomer([DataSourceRequest] DataSourceRequest request, APPLICANT applicant) 
    { 
     var customerToUpdate = dbContext.APPLICANTs.First(app => app.APPLICANT_ID == applicant.APPLICANT_ID); 

     TryUpdateModel(customerToUpdate); 

     dbContext.SaveChanges(); 

     return Json(ModelState.ToDataSourceResult()); 
    } 

    public ActionResult InsertCustomer([DataSourceRequest] DataSourceRequest request, APPLICANT customerToAdd) 
    { 
     if (ModelState.IsValid) 
     { 
      dbContext.APPLICANTs.Add(customerToAdd); 
      dbContext.SaveChanges(); 
     } 

     return Json(new[] { customerToAdd }.ToDataSourceResult(request)); 
    } 

    public ActionResult DeleteCustomer([DataSourceRequest] DataSourceRequest request, APPLICANT applicant) 
    { 
     var customerToDelete = dbContext.APPLICANTs.First(app => app.APPLICANT_ID == applicant.APPLICANT_ID); 

     if (customerToDelete != null) 
     { 
      dbContext.APPLICANTs.Remove(customerToDelete); 
      dbContext.SaveChanges(); 
     } 

     return Json(new[] { customerToDelete }.ToDataSourceResult(request)); 
    } 

我的上下文:

public partial class APPLICANT 
    { 
     public int APPLICANT_ID { get; set; } 


     public string APPLICANT_LastName { get; set; } 
     public string APPLICANT_FirstName { get; set; } 
     public string APPLICANT_MiddleName { get; set; } 
     public string APPLICANT_Address { get; set; } 

     public string APPLICANT_City { get; set; } 
     public string APPLICANT_ZipCode { get; set; } 

     public string APPLICANT_Phone { get; set; } 

     public string APPLICANT_Email { get; set; } 


    } 

指数:

@{ 
    ViewBag.Title = "Home Page"; 
} 
<h2>@ViewBag.Message</h2> 

@(Html.Kendo().Grid<KendoGridMvcCodeFirst.ViewModels.APPLICANT>() 
    .Name("APPLICANT") 
    .ToolBar(tb => tb.Create()) 
    .Pageable() 
    .DataSource(dataSource => dataSource.Ajax() 
     .Model(model => model.Id(c => c.APPLICANT_ID)) 
     .Read("GetAPPLICANT", "Home") 
     .Update("UpdateCustomer", "Home") 
     .Create("InsertCustomer", "Home") 
     .Destroy("DeleteCustomer", "Home")) 
    .Columns(cols => 
    { 
     cols.Bound(c => c.APPLICANT_LastName).Width(200); 
     cols.Bound(c => c.APPLICANT_FirstName).Width(200); 
     cols.Bound(c => c.APPLICANT_MiddleName).Width(200); 
     cols.Bound(c => c.APPLICANT_Address); 
     cols.Bound(c => c.APPLICANT_City); 
     cols.Bound(c => c.APPLICANT_ZipCode); 
     cols.Bound(c => c.APPLICANT_Phone); 
     cols.Bound(c => c.APPLICANT_Email); 

     cols.Command(cmd => 
     { 
      cmd.Edit(); 
      cmd.Destroy(); 
     }); 
    }) 
) 

*我的代码中缺少什么?谢谢那些可以帮助的人

回答

0

尝试使用返回标志Jason的行为允许获取。

Json(new [] { customerToAdd }.ToDataSourceResult(request),JsonBehavouir.AllowGet); 
+1

仍然得到错误..我编辑了我的查询代码,因为我的数据库已经建立,所以我只需要读取数据库 –

+0

尝试之前([DataSourceRequest] DataSourceRequest要求把申请人的领域上的数据。如果这不起作用,你可以检查控制器上的APPLICANT是什么? –

+1

先生,我已经编辑了错误消息上面的代码,但是又出现了另一个代码,这就是它...... {“值不能为空。\ r \ nParameter name:source“} ..你认为是什么导致这个错误..通过先使用数据库的方式,所以我必须获取我的数据库上的记录 –