0

我有一个如下所示的操作结果:

 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 指向不受当前路线影响的路线

4

0 回答 0