[英]Viewing foreignkey in Kendo UI Grid
我在Kendo
Grid中從一個表導航到另一個表時遇到一些問題。
在我的網格中,有一列是id,我當然更喜歡顯示名稱。 為此,我需要進入“語言表”。
這是我的代碼:
模型:
public DbSet<UserProfile> UserProfiles { get; set; }
public DbSet<Language> Language { get; set; }
public DbSet<NoteForm> Note { get; set; }
[Table("Language")]
public class Language
{
public string lang { get; set; }
[Key]
public int id { get; set; }
}
[Table("note")]
public class NoteForm
{
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[Display(Name = "Title")]
public string Title { get; set; }
[Required]
[Display(Name = "Text")]
public string Text { get; set; }
[Required]
[Display(Name = "Language")]
[ForeignKey("Language")]
public int languageId { get; set; }
[Key]
public int id { get; set; }
public int userId { get; set; }
}
查看:
@(Html.Kendo().Grid<DevelopmentNotesProject.Models.NoteForm>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.Title).Width(200).ClientTemplate(string.Format("{0}...", "#= formatter(Title) #"));
columns.Bound(c => c.Text).Width(450).ClientTemplate(string.Format("{0}...", "#= formatter(Text) #"));
columns.ForeignKey(p => p.LanguageId, (System.Collections.IEnumerable)ViewData["Language"], "id", "lang").Title("Language").Width(100);
columns.Command(command => { command.Edit(); command.Destroy(); });
})
.HtmlAttributes(new { style = "height: 380px;" })
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource // Configure the grid data source
.Ajax() // Specify that ajax binding is used
.Read(read => read.Action("Notes_Read", "MyNotes")) // Set the action method which will return the data in JSON format
.Destroy(update => update.Action("Notes_Destroy", "MyNotes"))
.Update(update => update.Action("Notes_Update", "MyNotes"))
.Model(model =>
{
model.Id(p => p.id);
})
)
.Selectable()
)
在查看代碼中,我嘗試編寫:
columns.ForeignKey(p => p.Language.id, (System.Collections.IEnumerable)ViewData["Language"], "id", "lang").Title("Language").Width(100);
但是我一直收到以下錯誤:
錯誤2無法將lambda表達式轉換為類型'string',因為它不是委托類型
需要一些建議和提示,以解決此處可能出現的問題以及如何解決此問題。
我只是嘗試這樣做,沒有錯誤。 您正在使用哪個IDE,並且嘗試過清理並重建?
只是以為我會在這里回答,以防萬一您想接受它作為答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.