2010-08-31 29 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

回答