views:

55

answers:

1

I have an actionresult that looks like:

 public ActionResult MyFriends(Guid? friendId)
 {
     if (friendId != null){
         return View(...);
     {
     else{
         return View(...);
     }
 }

If the friendId is supplied, I return a certain model that my view knows how to react to. Otherwise, if no friendId is given, the view renders accordingly.

<% if (Model.Friends != null) { %>
    <h1>Your friends</h1>
    [List of friends goes here]
<% } else if (Model.FriendId != null) { %>
    <% Html.RenderAction("_FriendDetails", "friends", new { area = "friends", id = Model.FriendId }); %>
    <%= Html.ActionLink("This link should not contain friendId", "myfriends") %>
    <%= Html.ActionLink("Why does this work", "myfriends", "friends", new {friendId = (Guid?)null }, null)%>
<% } %>

My problem is that when a friendId is specified, all my other links on the page that normally point to /myfriends all start linking to /myfriends/e586cc32-5bbe-4afd-a8db-d403bad6d9e0 making it really difficult to get back to the initial /myfriends output.

PLEASE NOTE that my project constraints require me to render this particular view using a single view. Normally, I would create a separate "details" view, but in this case, I'm using dynamic navigation and must render both outputs in a single view.

Also, I found a similar (unanswered) question here: http://stackoverflow.com/questions/697210/actionlink-pointing-to-route-not-affected-by-current-route

+1  A: 

Take a look at this similar question:

http://stackoverflow.com/questions/2651675/asp-net-mvc-html-actionlink-maintains-route-values

Peter
Looks like I'll have to create an "action only" method as I can't go though my entire application and place new { id = null } everywhere. Thanks!
Derek Hunziker