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();
});
})
)
*我的代碼中缺少什麼?謝謝那些可以幫助的人
仍然得到錯誤..我編輯了我的查詢代碼,因爲我的數據庫已經建立,所以我只需要讀取數據庫 –
嘗試之前([DataSourceRequest] DataSourceRequest要求把申請人的領域上的數據。如果這不起作用,你可以檢查控制器上的APPLICANT是什麼? –
先生,我已經編輯了錯誤消息上面的代碼,但是又出現了另一個代碼,這就是它...... {「值不能爲空。\ r \ nParameter name:source「} ..你認爲是什麼導致這個錯誤..通過先使用數據庫的方式,所以我必須獲取我的數據庫上的記錄 –