代码之家  ›  专栏  ›  技术社区  ›  Derek Hunziker

带有可选RouteValues的ActionResult影响视图上的其他ActionLinks

  •  0
  • Derek Hunziker  · 技术社区  · 15 年前

    我有一个actionResult,看起来像:

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

    如果 弗伦德 如果提供了,我将返回视图知道如何响应的某个模型。否则,如果没有 弗伦德 如果给定,视图将相应地呈现。

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

    我的问题是当 弗伦德 已指定,页面上通常指向/myfriends的所有其他链接都开始链接到/myfriends/ e586cc32-5bbe-4afd-a8db-d403bad6d9e0 使返回初始/myfriends输出非常困难。

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

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

    1 回复  |  直到 15 年前
        1
  •  1
  •   Community Mohan Dere    9 年前