i have model course, model component , model evaluation:
public class course { public virtual int courseid { get; set; } public virtual string name { get; set; } public virtual list<component> components { get; set; } public virtual list<userprofile> users { get; set; } public virtual list<evaluation> evaluation { get; set; } } public class component { public virtual int componentid { get; set; } public virtual int courseid { get; set; } public virtual course course { get; set; } public virtual string namecomp { get; set; } } public class evaluation { public virtual int evaluationid { get; set; } public virtual int courseid { get; set; } public virtual course course { get; set; } public virtual int userid { get; set; } public virtual userprofile user { get; set; } public virtual int grade { get; set; } }
i need show in view table users, components created , grade each one. tried way:
@model sgp.models.course <table> <tr> <th> username </th> @foreach (var x in model.components) { <th> @html.displayfor(modelitem => x.namecomp) </th> } <th></th> </tr> @foreach (var item in model.evaluation) { <tr> <td> @html.displayfor(modelitem => item.user.username) </td> @foreach (var x in model.components) { <td> @html.displayfor(modelitem => item.grade) </td> } <td> </td> </tr> }
but gives me components in 1 column, , need 1 column each component, , grade each one:
the code have gives this:
username - component1component2component3 test - 12 test - 13 test - 10 (example of result username , grades)
and need:
username - component1 - component2 - component3 test - 12 - 13 - 10 (example of result username , grades)
how can this? thanks
the definition of evaluations in course should be:
public virtual igrouping<string, evaluation> evaluations { get; set; }
the code should be:
@model sgp.models.course <table> <tr> <th> username </th> <th> @foreach (var x in model.components) { @html.displayfor(modelitem => x.namecomp) } </th> <th></th> </tr> @foreach (var group in model.evaluations) { <tr> <td> @html.displayfor(modelitem => group.key) </td> @foreach (var item in group) { <td> @html.displayfor(modelitem => item.grade) </td> } <td> </td> } </tr>
Comments
Post a Comment