Q
Q
Quber2014-08-18 09:55:18
ASP.NET
Quber, 2014-08-18 09:55:18

How to display Join request in ASP.NET View?

Controller

var comments = 
    from n in db.Comments
    join f in db.Files
    on n.ID
    equals f.CommentId
    where n.TreatmentID == id
    select new { Comment = n, File = f };

ViewBag.Comments = comments.ToList();

View
@foreach (var comment in ViewBag.Comments)
{
    @comment
}

Output:
{ Comment = MvcApplication.Models.Comment, File = MvcApplication.Models.File }

The Comment table has an Author field. I need to get it out, but I can't figure out how. I've looked all over stackoverflow but can't find anything useful. The task seems not difficult, but it has already spent a lot of time on its solution. If you do not use join, then everything is simple there. But how to output data using join?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orlangur25, 2014-08-19
@Orlangur25

good afternoon.
try using typed view (@model )
and then it will be
@foreach (var comment in Model)
{
@comment .Author
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question