etechpartner
etechpartner

Reputation: 660

Conditional Routing?

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>

<% } %>

Upvotes: 1

Views: 401

Answers (1)

ten5peed
ten5peed

Reputation: 15900

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

Upvotes: 3

Related Questions