简体   繁体   中英

Create url in ASP. NET MVC

I am developing an application in asp.net mvc and I want to create a url (You will see below).

I have already seen that there is this question @Html.ActionLink with the item Name as a link that does not answer my needs

@foreach (var item in Model) {
    <tr>
                
        <td>
            @Html.DisplayFor(modelItem => item.Data)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>   
        <td>
            @Html.DisplayFor(modelItem => item.NextTurnPlayer)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.State)
        </td>
        <td>
            @if(item.State.Equals("Conclusa")){
                @Html.DisplayFor(modelItem => item.Winner)
            }
        </td>
        <!--se non c'è neancora il secondo giocatore e il giocatore non è quello che ha creato la partita mostro partecipa-->
        @if(item.UsernamePlayer2 == null && item.UsernamePlayer1 != HttpContext.Current.User.Identity.Name){
            <td>
                @Html.ActionLink("Partecipate", "Partecipate", "Manage", new { Id= (string) @item.Name}, null)
            </td>
        }<!--se non ci sono entrambi giocatori e il giocatore loggato fa parte del match mostro gioca-->
        @if(item.UsernamePlayer2 != null && (item.UsernamePlayer1 == HttpContext.Current.User.Identity.Name || item.UsernamePlayer2 == HttpContext.Current.User.Identity.Name)){
            <td>
                @Html.ActionLink("Play!", "Game", "Manage", new { Id= (string) @item.Name}, null)
            </td>
        }
    </tr>
}

It gives me the following url:

https://localhost:44398/Manage/Partecipate/Ciao

But i want to have

https://localhost:44398/Manage/Partecipate?Name=Ciao

您是否尝试将路由参数名称更改为Name

@Html.ActionLink("Partecipate", "Partecipate", "Manage", new { Name = item.Name}, null)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM