tags:

views:

56

answers:

1

I have a simple partial view. The main part of which is listed below. How can I have the ActionLinks resolve properly when this partial view is rendered on a page that is managed by a different controller. In other words - this partial view shows Project Areas for a given Project. What if this PV shows up on a page being managed by the Project Controller. The Default route behavior here would try to have the code execute the /Project/Edit or Project/Detail . Thats not really what I need. Instead I need it to go to /ProjectArea/Edit for example. How is that accomplished in this case?

 <% foreach (var item in Model) { %>

    <tr>
        <td>
            <%= Html.ActionLink("Edit", "Edit", new { id=item.ProjectAreaId }) %> |
            <%= Html.ActionLink("Details", "Details", new {id=item.ProjectAreaId })%>
        </td>
        <td>
            <%= Html.Encode(item.Name) %>
        </td>
    </tr>

<% } %>
+2  A: 

You'll need to use the ActionLink overload that takes a controller string. I think it's signature looks like:

HtmlHelper.ActionLink(string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)

Is there a property on the 'item' object that you could use to discern the controllerName? Maybe set some other viewdata value in the controller that you can throw in as the controllerName...?

HTHs, Charles

Charlino
Somehow I thought there might be something more solid in use. I am thinking maybe having a base model and some sort of property for the partial view that points to its parent or its controller ... I guess thats why I am asking because I am not sure what the best practice is
etechpartner