2010-08-31 31 views
0

其他actionlinks我有,看起来像一个ActionResult:的ActionResult可选routevalues影响的观点

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

如果friendId提供,我返回我的看法知道如何反应有一定的模式。否则,如果没有给出friendId,则视图会相应地呈现。

<% 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)%> 
<% } %> 

我的问题是,当一个friendId指定,在页面上我的所有其他链接通常指向/ myfriends都开始链接到/ myfriends/e586cc32-5bbe-4afd-a8db-d403bad6d9e0使得它真的很难回到初始/ myfriends输出。

请注意,我的项目约束要求我使用单个视图渲染此特定视图。通常情况下,我会创建一个单独的“细节”视图,但在这种情况下,我使用的是动态导航,并且必须在一个视图中呈现两个输出。

而且,我发现了一个类似的(未回答)的问题在这里:ActionLink pointing to route not affected by current route

+0

请出示您在视图中使用的代码。 – Sruly 2010-08-31 19:58:08

+0

谢谢!我已更新帖子以包含我的观点。注意RenderAction代码下面的ActionLink。尽管我没有为requestId指定路由值,但它链接到/ myfriends/e586cc32-5bbe-4afd-a8db-d403bad6d9e0 – 2010-08-31 20:32:25

回答