Tuesday, 15 March 2011

c# - Not getting results in related tables using EF 5 and MVC 4 -



c# - Not getting results in related tables using EF 5 and MVC 4 -

brand new c#/asp.net...

i have 2 tables: administrators , administratorsrights. in administrators table, each administrator has administratorsrightsid. administrators class (model):

public partial class administrator { [key] public int administratorid { get; set; } [required] public int administratorsrightsid { get; set; } [required] public string username { get; set; } [required] public string lastname { get; set; } [required] public string firstname { get; set; } [required] public string standardid { get; set; } public virtual administratorsright rightslevel { get; set; } }

this controller:

public actionresult index() { homecoming view(db.administrators.tolist()); }

this view (razor):

@foreach (var item in model) { <tr> <td> @html.displayfor(modelitem => item.rightslevel) </td> <td> @html.displayfor(modelitem => item.username) </td> <td> @html.displayfor(modelitem => item.lastname) </td> <td> @html.displayfor(modelitem => item.firstname) </td> <td> @html.displayfor(modelitem => item.standardid) </td> <td> @html.actionlink("edit", "edit", new { id=item.administratorid }) | @html.actionlink("details", "details", new { id=item.administratorid }) | @html.actionlink("delete", "delete", new { id=item.administratorid }) </td> </tr>

}

everything shows except item.rightslevel in view. trying show name opposed id (system administrator, not "1"). i'm not surprised isn't working because haven't told column @ problem is, don't know that. i'm guessing model isn't right suspect logic should occur there.

that depend on administratorrights table, , fields have. news can go farther levels in displayfor helper have pull right field:

@html.displayfor(modelitem => item.rightslevel.rightslevelname)

where rightslevelname actual name of field trying show.

c# entity-framework asp.net-mvc-4 entity-relationship

No comments:

Post a Comment