views:

31

answers:

2

hello, What is the best way to display the username instead of the Author_Id (foreign Key) when I display a list of records. I am using Linq to Sql on this project.

<% foreach (var item in Model) { %>    
<tr>
    <td>
        <%= Html.Encode(item.Title) %>
    </td>
    <td>
        <%= Html.Encode(item.Author_Id) %>

<% } %>

I'm wondering if I have to pass something from the controller or if I can use lamda expressions to call a particular field based on the foreign key value.

A: 

By this point your ViewModel should already contain the username. You should aggregate the data in the controller when building your list of items in the model you pass to the page.

MattC
+2  A: 

IF your FK was in place when you built your model, you should have an Author property on your model that links to the author table, then you can do Model.Author.Name.

Paddy
Thanks, this was the syntax I was looking for.
Victor