I'm working on a MVC 3.0 application. I have a list of persons from my database, each of them have a relation to another table in the database called area.
The person DTO
public class Person
{
int PersonId {get; set;}
string Name { get; set;}
int AreaId {get;set;}
}
Now in my MVC view i would like to create links to area views using actionlinks, and i would like the linktext to be the area name, and not the area Id. My markup looks like this:
@foreach (var item in Model)
{
<tr>
<td>@Html.ActionLink(item.Name, "Edit", new { item.PersonId })</td>
<td>@Html.ActionLink(item.AreaId.ToString(), "ListArea", "Area", new { item.AreaId}, null)</td>
<td>@using (Html.BeginForm("Delete", "Person"))
{
@Html.Hidden("PersonId", item.PersonId)
<input type="submit" value="Delete" />
}
</td>
</tr>
}
It's the second ActionLink where i would like to change the item.AreaId.ToString() to the area name. I was thinking of adding a:
Html.RenderAction("AreaName", "Area", new {item.AreaId})
And in the action method I would retrive the area name from the database.
What am I doing wrong?
Thank you in advance.