1

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.

1 Answers1

0

If my understanding is correct, why don't you change the action link text to fetch area name as follows:

@Html.ActionLink(item.AreaINameToString(), "ListArea", "Area", new { item.AreaName}, null)</td>

Regards Pavan.G

Pavan Kumar
  • 190
  • 2
  • 8
  • I'm sorry, I don't have access to the Name property of the area, it is stored in the database, I only have the AreaId referencing to a AreaName. If that makes any sence. – Jacob Brinth Dec 03 '12 at 20:01